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
 Select

Author  Topic 

hoda02
Starting Member

1 Post

Posted - 2012-08-19 : 11:12:52
Hi,

I have a list like this in a table

Number Block
1.........2
2.........2
3.........4
4.........5

It means that Number 1,2 can go to block 2 only, and number 3 can go to block 4 only and etc.

And I have bellow data to another table:

Number Block date
1.........2 2001/01/01
1.........2 2001/01/02
1.........2 2001/01/03
1.........3 2001/01/04
2.........2 2001/01/01
2.........3 2001/01/03

It means that Number 1 has gone to Block 2 and 3 and number 2 has gone to block 2 and 3

Now I want to select some numbers they have gone in some blocks except for their blocks. It means Number 1 in date 2001/01/04 and Number 2 in date 2001/01/03

How can I do this?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-19 : 13:48:33
[code]
SELECT *
FROM Table2 t2
WHERE NOT EXISTS (SELECT 1 FROM Table1 WHERE Number = t2.Number AND Block = t2.Block)
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -