Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need to do a simple join? Maybe?

Author  Topic 

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-01-10 : 16:10:41
I have two dbs. Arrest and Arresttocompare. The latter was set up with "new" data just to see where there are entries that don't exist in the former. I only used two unique fields in the three tables in the new db. I need to see the instances where the field Arrestno exists in Arresttocompare but does not exist in Arrest. I'm assuming i need to use a join, but what would it look like? The following is not giving me the results i seek.

SELECT Arrest.ARRESTNO, Arrest_1.ARRESTNO
FROM ARREST.dbo.Arrest Arrest
INNER JOIN
ARRESTtocompare.dbo.Arrest Arrest_1
ON (Arrest.ARRESTNO <= Arrest_1.ARRESTNO)

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-10 : 16:17:23
>> where the field Arrestno exists in Arresttocompare but does not exist in Arrest
SELECT *
FROM ARRESTtocompare.dbo.Arrest Arrest_1
LEFT JOIN ARREST.dbo.Arrest Arrest
ON Arrest.ARRESTNO = Arrest_1.ARRESTNO
WHERE Arrest.ARRESTNO IS NULL

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

WJHamel
Aged Yak Warrior

651 Posts

Posted - 2012-01-10 : 17:01:50
at'll do. thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-11 : 01:16:05
Also

SELECT *
FROM ARRESTtocompare.dbo.Arrest Arrest_1
WHERE NOT EXISTS (SELECT 1 FROM ARREST.dbo.Arrest Arrest
WHERE Arrest.ARRESTNO = Arrest_1.ARRESTNO)



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -