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 |
ppatel112
Starting Member
35 Posts |
Posted - 2012-07-05 : 19:43:55
|
Hi Guys,i am facing a query where there are two columns in sql table called ['BATCH_URL_101-6896$'].data1 500 501502504505507data2501502505507508514i need a sql query to compare data2 column to data1 column and put the results in third column data3 data3 will need to look likedata3500504505please advise.regards,parth |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-07-05 : 20:03:20
|
What is the logic you want to use? First I thought you wanted values that are in data1 column, but not in data2 column. 500 and 504 match that criterion. But 505 is in both tables, yet you have that in your expected results. |
 |
|
ppatel112
Starting Member
35 Posts |
Posted - 2012-07-05 : 20:06:24
|
oops sorry not 505 only 500 and 504please advise |
 |
|
ppatel112
Starting Member
35 Posts |
Posted - 2012-07-05 : 20:48:33
|
can someone help?? |
 |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-07-05 : 21:51:30
|
One of these should work.-- 1.SELECT a.data1FROM ['BATCH_URL_101-6896$'] a LEFT JOIN ['BATCH_URL_101-6896$'] b ON a.data1 = b.data2WHERE b.data2 IS NULL;-- 2.SELECT a.data1FROM ['BATCH_URL_101-6896$'] aWHERE NOT EXISTS (SELECT * FROM ['BATCH_URL_101-6896$'] b WHERE b.data2=a.data1); |
 |
|
ppatel112
Starting Member
35 Posts |
Posted - 2012-07-05 : 22:01:52
|
thanks the first one worked |
 |
|
|
|
|