Saturday, 15 February 2014

MYSQL - SELECT AS alias to be used in subquery -



MYSQL - SELECT AS alias to be used in subquery -

i want able utilize 1 of items selecting farther downwards in sub query. can see in illustration have set "variable" in question 100 in reality going dynamic number need able access in subquery.

insert users_friends (userid, friendid) select 77, id noob users email = 'a@g.com' , not exists (select * users_friends userid = 77 , friendid = noob) limit 1

i'm not sure understand question, not exists works left bring together , null. think work:

select 77, @noob users u bring together (select @noob:= 100) r left bring together users_friends uf on u.userid = uf.userid , uf.friendid = @noob email = 'a@g.com' , uf.userid null

and here sql fiddle.

mysql select subquery

No comments:

Post a Comment