Results 1 to 4 of 4

Thread: table joining

  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unanswered: table joining

    Hello

    please forgive me if this is really easy, but I am new to the world of mysql and am on a fairly tight timeframe.
    I am trying to find all the values in one table which don't appear in another.
    ie, I have a database x, which has a table, y, which lists shots in it.
    I have another database a, which has another table, b, which also lists all the shots. I need to know which shots in x.y don't appear in a.b

    simple, I am sure, but it's driving me nuts.

    thanks!
    sez

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    PHP Code:
    select shots
      from x
    .as t1
    left outer
      join a
    .as t2
        on t1
    .shots t2.shots
     where t2
    .shots is null 
    assuming the two databases are accessible by the same mysql server
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2004
    Posts
    480
    You might have to use select t1.shots instead of select shots
    right at the beginning of Rudy's solution. I tried his solution since I hadn't done selects from multiple dbs before and got an ambiguous field error until I changed to t1.shots.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    DOH!

    thanks, guelphdad
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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