SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Join tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jfm
Posting Yak Master

145 Posts

Posted - 04/23/2013 :  11:08:55  Show Profile  Reply with Quote
Hi there,

Im trying to extract the info that is not matching from two different tables:

Each table has 15 columns, in which they have a common ID_Col.

I need to extract all data from Table2 if the ID_Col doesn't match with Id_Col from table1.

By using this query:

SELECT Table1.Id_Col, Date FROM Table1
LEFT OUTER JOIN Table2
ON Table2.Id = Table1.Id
GROUP BY Table1.Id_Col, Date

I have all the info and NULL values if they are not matching.. instead of NULL values I will need the info.

Any tip?

Thanks

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/23/2013 :  11:36:58  Show Profile  Reply with Quote
Can you show us table descriptions, some data and expected output
Go to Top of Page

jfm
Posting Yak Master

145 Posts

Posted - 04/23/2013 :  11:42:07  Show Profile  Reply with Quote
Sure:

Table_F
Col_Name, Col_Place, Col_Zip, Col_Car, Col_House, Col_Id

Table_S
Col_Name, Col_Date, Col_End, Col_Car, Col_Mind, Col_Id

Extraction:

All the info from Table_S if the Col_id is not matching Col_Id from Table_F

This way I will short out all the clients that i miss in Table_F but they are in Table_S

Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/23/2013 :  12:49:50  Show Profile  Reply with Quote
multiple ways

1.
SELECT *
FROM Table_S s
WHERE NOT EXISTS (SELECT 1 FROM Table_F WHERE Col_Id = s.Col_Id)

2.
SELECT s.*
FROM Table_S s
WHERE Col_Id NOT IN (SELECT Col_Id FROM Table_F)

3. 
SELECT s.*
FROM Table_S s
LEFT JOIN Table_F f
ON f.Col_Id = s.Col_Id
WHERE f.Col_Id IS NULL


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.58 seconds. Powered By: Snitz Forums 2000