* Daren Cotter > I need to run a query that selects the usernames of all the members a > particular member has referred on the second level. So member 5 refers > 10, 11, and 12, I need the usernames of everyone referred by 10, 11, or > 12. Currently I run one query to get 10, 11, 12, make that a string, > then do another query with member in ($string). Is there a way to do it > with a nested query? Something like: > > SELECT username FROM members WHERE referer IN (SELECT id FROM members > WHERE referer = 5);
Sub-selects are not supported in mysql, but you can do this using a join, something like this: SELECT m1.username FROM members AS m1, members AS m2 WHERE m1.referer = m2.id AND m2.referer = 5; <URL: http://www.mysql.com/doc/J/O/JOIN.html > <URL: http://www.mysql.com/doc/S/E/SELECT.html > -- Roger --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php