开发者

MySql Not accessing parent in subquery?

开发者 https://www.devze.com 2023-01-17 22:13 出处:网络
I get the error Unknown column \'m.id\' in \'on clause\' all my tables have a field called id. It appears to occur in my subquery. I use m.id in my join. So what the heck is going on? shouldnt i be

I get the error

Unknown column 'm.id' in 'on clause'

all my tables have a field called id. It appears to occur in my subquery. I use m.id in my join. So what the heck is going on? shouldnt i be able to access that var? how do i access media.id from my subquery? Also is the and not (select 1 part right? i am trying to exclude that tag.

select m.id from media m 
join tag_name as n0 on n0.title = @a0 
    join media_tag as t0 on t0.media_id=m.id AND t0.tag_id = n0.id
where 1 
AND not (select 1 from tag_name as n1
    join media_tag as t1 on t1.media_id=m.id AND t1.tag_id = n1.id
    whe开发者_如何学Cre n1.title = @a1) 
order by m.id desc;


Move the check of t1.media_id=m.id to the where clause and it works (for me, anyway):

select m.id from media m 
join tag_name as n0 on n0.title = @a0 
    join media_tag as t0 on t0.media_id=m.id AND t0.tag_id = n0.id
where 1
AND not (select 1 from tag_name as n1
    join media_tag as t1 on t1.tag_id = n1.id
    where t1.media_id=m.id AND n1.title = @a1) 
order by m.id desc;
0

精彩评论

暂无评论...
验证码 换一张
取 消