List:General Discussion« Previous MessageNext Message »
From:SGreen Date:August 9 2004 4:16pm
Subject:Re: Selecting data from 2 tables.
View as plain text  
I think a quick way to write this query would be 
(http://dev.mysql.com/doc/mysql/en/UNION.html):

( SELECT magazine FROM pages )
UNION DISTINCT
( SELECT magazine FROM pdflog )
ORDER BY magazine;

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

Ed Curtis <ed@stripped> wrote on 08/09/2004 12:10:16 PM:

> 
> 
> > What he is really missing is the WHERE clause that matches something 
from
> > pages with something from pdflog....    Without it he is requesting a
> > Cartesian product of his tables (every combination of each row from 
both
> > tables).
> >
> > I prefer to define my JOINS *explicitly*. It makes it harder to
> > accidentally define Cartesian products):
> >
> > SELECT DISTINCT company
> > FROM pages
> > INNER JOIN pdflog
> > ON ...some condition goes here ....
> > ORDER BY company
> >
> > Shawn Green
> > Database Administrator
> > Unimin Corporation - Spruce Pine
> 
>  OK now I really really feel stupid. Now that I've been given the 
correct
> way this particular person wants this done. What I need to produce is a
> distinct list from pages.magazine and pdflog.magazine without a 
condition.
> Just a list of all data in these table columns without duplicates.
> 
> Ed
> 
> 

Thread
Selecting data from 2 tables.Ed Curtis9 Aug
  • Re: Selecting data from 2 tables.Martijn Tonies9 Aug
    • Re: Selecting data from 2 tables.Ed Curtis9 Aug
    • Re: Selecting data from 2 tables.SGreen9 Aug
      • Re: Selecting data from 2 tables.Ed Curtis9 Aug
      • Re: Selecting data from 2 tables.Ed Curtis9 Aug
        • Re: Selecting data from 2 tables.SGreen9 Aug
          • Re: Selecting data from 2 tables.Ed Curtis9 Aug
            • Re: Selecting data from 2 tables.SGreen9 Aug
      • Re: Selecting data from 2 tables.Martijn Tonies9 Aug