tags:

views:

27

answers:

1

I have a problem that I can't seem to solve. What I am trying to do is find unique columns based in table A that doesn't exist in other table B and store them in table B. Something on the lines of

 SELECT DISTINCT(A.FNAME), A.LNAME from ADDRESS A WHERE NOT EXIST 
                              (SELECT DISTINCT(B.FNAME),B.LNAME
                               FROM ADDRESSLIVE B)

but that doesn't seem to work, my ideal logic is to use the FNAME column and LNAME column together as a unique id, since those columns separately can be duplicates. Can someone inform me of what I am doing wrong, or what I am trying to do if its even possible?

+4  A: 
 SELECT DISTINCT A.FName, A.LName FROM Address A
    WHERE NOT EXISTS 
      (SELECT * FROM AddressLive B WHERE B.FName = A.FName AND B.LName = A.LName)
Larry Lustig
Thanks.. That was it
Jake
Always a pleasure to be of assistance.
Larry Lustig
Keep in mind that correlated subqueries can be very slow with large datasets. This could also be done with a LEFT JOIN and it wouldn't have the correlated subquery problem.
David-W-Fenton