#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    82
    Rep Power
    11

    Compare tables in two databases


    I have the same table in two different databases on the same server and am trying to find records where the same address matches up. I'm using the query below but not getting the correct results, any help is appreciated:

    Code:
    SELECT * from database1.valid as t1
    LEFT JOIN  database2.valid as t2
    ON t1.ADDR=t2.ADDR where t1.ADDR != '' and t2.ADDR != ''
    thanks
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    You have the right syntax so if it's not returning the right results then it's not using the correct logic.

    What's wrong with them? What were you expecting to get and what did you actually receive?
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Originally Posted by utexas10
    ... trying to find records where the same address matches up
    try an INNER JOIN
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo