SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unique rows across multiple tables

    Hi,

    Is there a way to find all the unique rows across more than one tables? It's like stacking 2 tables and run this SELECT DISTINCT name FROM combinedTable

    I tried
    SELECT DISTINCT a.name FROM a,b,c,d.... but I think it just select those in table a only. What I'd like is across all tables.

    Thanks.

  2. #2
    SitePoint Addict EvilDoppler's Avatar
    Join Date
    Dec 2001
    Location
    Perth, Australia
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink

    Easiest way to run that is to use sql joins..

    your sql query would look like this (if i'm getting the question right):

    Code:
    SELECT DISTINCT a.name, b.name, c.name 
    FROM tableA as a, tableB as b, tableC as c 
    WHERE a.name=b.name AND c.name=a.name
    the a. represents a table .. so tableA as a is the pointer to which table you want to select the field from.

    the above AND statement will get you the same output from each table (tableA, tableB, tableC) but you dont have to run your AND statement on selected fields..the selected fields are only those you wish to display or manipulate further in the script. So it is done like this:
    Code:
    SELECT DISTINCT a.name, b.name, c.name 
    FROM tableA as a, tableB as b, tableC as c 
    WHERE a.state='Queensland' 
    AND b.postcode='6000' 
    AND c.areacode='08'
    Anyways, hope that helps a bit - am sick as a dog and not sure i'm making any sense.

    cheers
    Last edited by EvilDoppler; May 27, 2002 at 21:23.
    * Due to the last tax raise our prices has risen
    * - answers w/o thought $1 - answers w/ thought $3
    * - correct answers $10
    * - Dumb stares are still free


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •