View Single Post

   
  #8 (permalink)  
Old 02-28-2008, 08:13 AM
Captain Paralytic
 
Posts: n/a
Default Re: Joining 2 columns from the same table


PleegWat wrote:
> In article <1158826754.185026.146540@e3g2000cwe.googlegroups. com>,
> Captain Paralytic says...
> >
> > PleegWat wrote:
> > > In article <1158753035.660362.86060@m7g2000cwm.googlegroups.c om>, Nicos
> > > says...
> > > > Hello,
> > > > i have a table (Matches) than have the columns listed below:
> > > > matchId, homeTeam, awayTeam, result
> > > >
> > > > I want to list all the teams DISTINCT both home and away teams.
> > > > How do i do that?
> > > >
> > > > Best regards,
> > > > Nicos
> > >
> > > Maybe:
> > >
> > > SELECT DISTINCT `Team`
> > > FROM (
> > > SELECT `homeTeam` AS `Team`
> > > FROM `Matches`
> > > UNION
> > > SELECT `awayTeam` AS `Team`
> > > FROM `Matches`)
> > > --
> > > PleegWat

> >
> > That does the same as my ealier query as UNION keeps only distinct
> > values (as opposed to UNION ALL which keeps all values)

>
> Well, I knew the syntax, but I never actually used unions before. Didn't
> know it was distinct by default, assumed it wasn't since most stuff
> doesn't seem to be.
> --
> PleegWat

That's the beauty of posting responses to other people's queries. You
learn more when other's comment on your post. Admittedly some people
correct others in a rather less than sympathetic manner, but the
outcome of learning more still makes it worth it (IMHO).

Reply With Quote