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 |
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-11-30 : 21:40:38
|
| Hi,I have following situation. I need to get a result set based on the 2 different kind of inputs. I don't have the SQL query details at this point to share but any examples of how to do this would be very helpful as a starting point. Please note that 1, 2 .. are distinct records based on some criteria.Ex A={1, 2, 3, 4} ; B={1,4,6,7} ; Therefore: AnB={1,4}A={1, 2, 3, 4} ; B={6,7} ; Therefore AnB={1,2,3,4} How can I get this contrary result set. Any ideas would be helpful at this point!!SA |
|
|
kbhere
Yak Posting Veteran
58 Posts |
Posted - 2009-12-01 : 02:52:45
|
| You can get these using joins.. In first case you can use INNER JOIN,SELECT A.value AS AnB FROM A INNER JOIN B ON A.value = B.valueAnd in 2nd case you can use LEFT JOIN,SELECT A.value AS AnB FROM A LEFT JOIN B ON A.value = B.valueI have posted this based on my assumption.. If you need exact result as per your need, then post the table structure and sample values..Balaji.K |
 |
|
|
agarwasa2008
Posting Yak Master
109 Posts |
Posted - 2009-12-01 : 14:47:19
|
| select Name,id from productE8400 NULLE8600 0select Name,id from product2E8600 1E8200 0Queries:-- 0 recordsSELECT Name, id FROM productwhere id = 0intersectSELECT Name, id FROM product2where id = 1---------------------------------------------1 recordsSELECT Name, id --1FROM product2where id = 1exceptSELECT Name, id --0FROM productwhere id = null----------------------------Please note that this is a simple scenario but I want to combine these 2 queries to create 1 result set which displays intersect if something is in common and if there is nothing in common then dispalys the original result set as A shown here. Please advice.Ex A={1, 2, 3, 4} ; B={1,4,6,7} ; Therefore: AnB={1,4} the result of intersectionA={1, 2, 3, 4} ; B={6,7} ; Therefore AnB={1,2,3,4} the result set from except.SA |
 |
|
|
|
|
|
|
|