Click here to Skip to main content
15,880,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello evry body
this my first question in codeproject

i have 2 tables ( table1 , table2 )

table2 is part of table1

i want to show data from table1 where are not in table2

sorry for my English
Posted
Comments
ZurdoDev 10-Feb-12 14:38pm    
Several different ways to do that. You can do a WHERE NOT EXISTS or WHERE NOT IN but you need to get the SQL written and then we can help.

If you have

Table1
 id
 name

and

Table2
 id
 name


Then you can do

SQL
SELECT Table1.* FROM Table1
LEFT JOIN Table2 
   ON Table1.ID = Table2.ID and Table1.Name = Table2.Name
WHERE Table2.ID is NULL


Essentially you're saying "Try to Join table 1 and Table 2 based on similar rows, and only return those rows from Table1 that don't exist in Table2"
 
Share this answer
 
Comments
Espen Harlinn 11-Feb-12 6:13am    
5'ed!
It's a simple task. Take a look at this article to learn everything about JOINs
Visual Representation of SQL Joins[^]
BTW it has the answer
 
Share this answer
 
Comments
Espen Harlinn 11-Feb-12 6:13am    
5'ed!
You want to filter your data. The obvious way to do that is to just change the SQL that fills table2, to only put the data you want in there. Otherwise, copy the data to a new source and filter it.

And welcome to Code Project.
 
Share this answer
 
thanks every one : i found the soulution with this query


SELECT * FROM Table1 WHERE ID NOT IN (SELECT ID FROM Table2)
 
Share this answer
 

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



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