On 26-Feb-2003 [EMAIL PROTECTED] wrote: > Yes , I had use this query statement in my MySQL server, > But I have a query about it. > Why are you use "WHERE a.groupname=b.groupname AND members.id=b.memberid > AND a.memberid=1"? > Can you give me a explain or give me a advise! >
Sure. mysql> SELECT DISTINCT members.* FROM members, groups as a, groups as b -> WHERE a.groupname=b.groupname AND members.id=b.memberid -> AND a.memberid=1; The 'a.memberid=1' clause looks up the groups that member 1 belongs to in the groups table (as a), giving 'group1' & 'group2'. Then it joins back against the groups table (as b) with the 'a.groupname=b.groupname' clause to get the folks that belong to these group(s). Finally the 'members.id=b.memberid' bit selects the records out of the members table, with the DISTINCT function suppressing any duplicates. Clear as mud? (I could've be a little more obvious if I'd put the 'a.memberid=1' clause first. Sorry ...) Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. (53kr33t w0rdz: sql table query) --------------------------------------------------------------------- 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