List:General Discussion« Previous MessageNext Message »
From:Sheryl Canter Date:February 26 2003 3:56pm
Subject:Re: Help needed with SQL...
View as plain text  
I've never seen opening a table twice and then doing a join back with
itself. Am I wording this correctly? Is that how to describe what you're

Thanks for posting this to the full list.

    - Sheryl

----- Original Message -----
From: "Don Read" <dread@stripped>
To: <Jun.Han@stripped>
Cc: <mysql@stripped>; <autumn@stripped>
Sent: Wednesday, February 26, 2003 5:11 AM
Subject: RE: Help needed with SQL...

On 26-Feb-2003 Jun.Han@stripped 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
> AND a.memberid=1"?
> Can you give me a explain or give me a advise!


mysql> SELECT DISTINCT members.* FROM members, groups as a, groups as b
    -> WHERE a.groupname=b.groupname AND
    -> AND a.memberid=1;

The 'a.memberid=1' clause looks up the groups that member 1 belongs to in
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

Finally the '' bit selects the records out of the
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 ...)

Don Read                                       dread@stripped
-- 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:   (the manual)           (the list archive)

To request this thread, e-mail <mysql-thread133397@stripped>
To unsubscribe, e-mail
Trouble unsubscribing? Try:

Help needed with SQL...M Wells26 Feb
  • RE: Help needed with SQL...Don Read26 Feb
RE: Help needed with SQL...Jun.Han26 Feb
  • RE: Help needed with SQL...Don Read26 Feb
    • Re: Help needed with SQL...Sheryl Canter26 Feb
    • Re: Help needed with SQL...Tore Bostrup26 Feb