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
 Comparison of data from two tables

Author  Topic 

duf
Starting Member

39 Posts

Posted - 2012-01-19 : 13:39:56
Table CN
CNID_____OPIS______KOD
1...........11............6109100
2...........12............5208900
3...........12............9895600
4...........13............4567890

After connecting the CN table with DBGrid (after taking into account other conditions) we finally can see two records:
CNID_____OPIS______KOD
2...........12............5208900
3...........12............9895600

Table OP should also contain two records and two values ??CNID: 2 and 3 But it contains only one value CNID: 2
Table OP
ID_____CNID_____RODZAJ
1..........2..........PX

What use a query to check whether the OP table contains all the values CNID ??shown in the DBGrid, 2 and 3?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-19 : 13:50:50
[code]-- to see which CNID's exist in CN table but not in OP table.
SELECT CNID FROM CN WHERE NOT EXISTS (SELECT * FROM OP WHERE OP.CNID=CN.CNID);
-- to see which CNID's exist in CN table and in OP table.
SELECT CNID FROM CN WHERE EXISTS (SELECT * FROM OP WHERE OP.CNID=CN.CNID);
[/code]
Go to Top of Page

duf
Starting Member

39 Posts

Posted - 2012-01-19 : 14:08:26
Thank You sunitabeck ;-)
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-01-19 : 14:20:22
Very welcome .)
Go to Top of Page
   

- Advertisement -