-1

I have been looking at examples in Stackoverflow but none have given me results, I have a query in which "select" there is an alias that I then need to use with a "LEFT OUTER JOIN" to compare it with the column of another table but when I execute it it generates an error of unknown column, I have been reading that a second JOIN is required but I do not know how to do it.

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(embed, '/', -2), '"', 1) as idvideo, embed, thumbnail, title,
MATCH(title, tags, category) AGAINST('peruvian food') as score 
FROM peruvian_food
LEFT OUTER JOIN peruvian_food_del ON (peruvian_food.idvideo = peruvian_food_del.id_video_del) 
WHERE MATCH(title, tags, category) AGAINST('peruvian food' IN BOOLEAN MODE) 
AND peruvian_food_del.id_video_del IS NULL
LIMIT 30

I am getting the following error:

#1054 - Unknown column 'idvideo' in 'on clause' 

1 Answer 1

1

The error is saying that the table peruvian_food does not contain a column named idvideo.

If we are attempting to reference the expression in the SELECT list that is assigned the alias idvideo, that reference is not allowed in the ON clause within the same SELECT. Even if a reference like that was allowed, we wouldn't qualify it with the peruvian_food. table name; there isn't a column named idvideo in that table.

Simplest workaround is to repeat the expression used in the SELECT list:

ON ( SUBSTRING_INDEX(SUBSTRING_INDEX(peruvian_food.embed, '/', -2), '"', 1) = ...

If we need to reference the idvideo alias, we would need to use an inline view, so that the column name was from a derived table.

We're just guessing at the specifiction... what it is we're trying to achieve. (I'm not even sure there was a question being asked; reads more like a status report than a question, so we're also just guessing at what question is being asked.)

1
  • it is true! ty for your help!
    – Kokox
    Oct 18, 2017 at 19:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.