tags:

views:

24

answers:

1

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
    where n1.title = @a1) 
order by m.id desc;
+1  A: 

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;
ysth
That solved it! I could swear syntax like this is valid in sqlite. If so then i am liking how relaxed/easy sqlite is and hope i dont run into too many problems with mysql
acidzombie24