Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
There are two same structure table in Database i.e. Table A and B. Table A contains 100 records and Table B contain 50 records which is already in Table A.

Write a sql query find records in Table A which is not in Table B (don't use "in" operator and subquery)  
Posted
Updated 22-Jul-14 19:22pm
v2
Comments
Peter Leow 22-Jul-14 23:36pm    
Sound like homework. What have you tried?

Hi
Hope this may help

SQL
select * from dbo.TableA A FULL OUTER JOIN dbo.TableB B ON A.ColName=B.ColName where B.ColName is null
 
Share this answer
 
Comments
Maciej Los 23-Jul-14 1:57am    
Looks perfect! 5!
Hi,

Look at below query also...

SQL
--Take a note...your selected columns in both tables should be same, here i am assuming as per your input
SELECT * from A
MINUS
SELECT * FROM B
--if require put where clause


Hope this will help you.


Cheers
 
Share this answer
 
Comments
CHill60 25-Jul-14 9:32am    
Question was tagged as SQL-Server 2008R2 - no such thing as MINUS. Perhaps you mean EXCEPT[^]
SQL
SELECT  a.*
FROM    Table1 A
        LEFT JOIN Table2 B
            ON A.name = B.name 
WHERE   B.Name IS NULL


Hope this helps you :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900