Page 1 of 1

ORDER BY in subquery not working

Posted: Thu Mar 24, 2011 8:03 am
by rhecker
Table A contains columns photo and id
Table B contains columns id, other_id and rank (primary index on id and other_id)

The following query correctly returns the result I want, except that it ignores my request to order by rank, and I need it to do that.

SELECT photo FROM A WHERE id= ANY(SELECT id FROM B WHERE other_id='$other_id')

Any suggestions?

Re: ORDER BY in subquery not working

Posted: Thu Mar 24, 2011 8:29 am
by Darhazer
join the tables :)

Code: Select all

SELECT photo FROM A INNER JOIN B USING (id) WHERE other_id='$other_id' ORDER BY rank

Re: ORDER BY in subquery not working

Posted: Thu Mar 24, 2011 10:38 am
by rhecker
Yes, I had suspected an inner join was the key, but those I wrote didn't work. Yours worked perfectly! Thanks!