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.
| Author |
Topic |
|
zhel04
Starting Member
38 Posts |
Posted - 2011-11-16 : 02:57:33
|
| How to query to get data with two conditions in one output.Conditions:1. idno existing in Table1 and idno not existing in Table22. Tbl1 idno = Tbl2 idno AND Tbl1 base <> Tbl2 baseExample:Tbl1 Tbl2idno base idno base123 50 123 80456 10 456 10789 20 789 50101 30 101 30102 40 104 50103 100 105 90OUTPUT:idno base123 50789 20102 40103 100Note: The data for output will come from Tbl1Thanks. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-16 : 03:25:31
|
| [code]SELECT t1.*FROM Tbl1 t1LEFT JOIN Tbl2 t2On t2.idno = t1.idno AND t2.base = t1.base WHERE t2.idno IS NULLorSELECT *FROM Tbl1 t1WHERE NOT EXISTS(SELECT 1 FROM Tbl2 WHERE idno = t1.idno AND base = t1.base[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|