Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 Different tables A and B. In Table A, i have id,name and in Table B, i have id,name and have some values in both tables.

For Ex:

Id Name
F001 A
F002 B
F003 C
F004 D
F005 E

Id Name
F002 B
F001 A
F005 E

Now, i have to get the missing values in table B from table A.
Is there any sqlite query for that. If no, Please give me the Solution for this case.

Ans Should be like this.

Id Name
F003 C
F004 D

Thanks in advance.
Posted
Updated 17-Jan-16 23:05pm
v2
Comments
ZurdoDev 12-Jan-16 10:00am    
What is considered a missing value? The combination of Id and Name? Or just Name? Either way, this is pretty simple. Where are you stuck?
TinkerBelly 18-Jan-16 5:06am    
I have included the Question here. Please Check. Thanks for your reply.

Try:
SQL
SELECT A.ID, A.Name FROM TableA A
LEFT JOIN TableB B ON B.name = A.name
WHERE B.ID IS NULL
 
Share this answer
 
Comments
John C Rayan 12-Jan-16 10:12am    
Looks the best solution to me. 5!
[no name] 12-Jan-16 10:14am    
A 5 for this. LEFT JOIN is usually much more performant then IN/EXISTS.
I reread your title and realized you just want to know which names are not in TableA that are in TableB.

For example:
SQL
SELECT Name
FROM TableB
WHERE Name NOT IN (SELECT NAME FROM TableA)
 
Share this answer
 
Try the EXCEPT Operator[^]:
SQL
SELECT
    ID,
    Name
FROM
    TableA

EXCEPT

SELECT
    ID,
    Name
FROM
    TableB
;

If you just want the missing names:
SQL
SELECT
    Name
FROM
    TableA

EXCEPT

SELECT
    Name
FROM
    TableB
;
 
Share this answer
 
v2

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