简体   繁体   中英

Mysql - Alias in Left Outer Join giving error

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' 

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM