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 |
wided
Posting Yak Master
218 Posts |
Posted - 2014-11-19 : 10:56:08
|
table1 header:col1 col2 col3 col4 col55 2014 2014-08-29 00:00:00.000 AB_TND 2014/06365 2014 2014-08-07 00:00:00.000 STUSID_USD 2014/0641Table2: detailscol1 col2 col3 col4 5 1 627801 6278015 2 532103 5321035 1 99 995 2 532405 532405my querySelect col1, col2, col3, col4table1 INNER JOIN table2ON table1.col1 = table2.col1where table1.col4 = 'STUSID_USD'the result is this:5 1 627801 6278015 2 532103 5321035 1 99 995 2 532405 532405i want to have this result:5 1 99 995 2 532405 532405what is the problem?thanks |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-11-19 : 12:49:35
|
You're joining on col1, which only has one value -- 5 -- in both tables, so all 4 rows are returned. Why do you think that the two rows you don't want should be excluded? If they were, SQL would have a bug!Put another way, what value in table1 should be used to restrict the rows retrieved in table2? Note that table.col4 won't do, since there is no column in table 2 with that value in any row. |
|
|
|
|
|