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 |
BitShift
Yak Posting Veteran
98 Posts |
Posted - 2006-09-27 : 16:49:21
|
stored procedure, with paramater @fparentidTABLE A--------idnamefdataTABLE B--------fidcfidwhere tableb.fid is tablea.idthe sql below gives be a resultset that has duplicates. its alomst as if the join is happening twice ?SELECT a.name,b.fid,b.cfid AS cform_idFROM bJOIN aON a.id = b.cfid AND b.fid = @fParentidORDER BY b.fidMy resultset lists the correct items, but the resultset has a duplicate result. For example, on one test i get 16 records, when I should only get 8. The last 8 are an exact copy of the 1st 8. What am i doing wrong ? |
|
snSQL
Master Smack Fu Yak Hacker
1837 Posts |
Posted - 2006-09-27 : 17:00:43
|
Sounds like there could be a problem with your data. Post the data for the example you gave by running these two queries (replace ? with the value you passed to the sp when you got the 16 rows.SELECT id, name FROM a WHERE id IN (SELECT cfid FROM b WHERE fid = ?)SELECT fid, cfid FROM b WHERE fid = ? |
 |
|
BitShift
Yak Posting Veteran
98 Posts |
Posted - 2006-09-27 : 17:28:52
|
quote: Originally posted by snSQL Sounds like there could be a problem with your data. Post the data for the example you gave by running these two queries (replace ? with the value you passed to the sp when you got the 16 rows.
You beat me to it. I had been beating my head for the last 2 hrs looking at my join, trying to figure out why I was getting duplicates...when in fact THERE WAS DUPLICATES in the data problem resolved |
 |
|
BitShift
Yak Posting Veteran
98 Posts |
Posted - 2006-09-27 : 17:29:12
|
remove this post |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-09-27 : 21:06:02
|
quote: Originally posted by BitShift remove this post
You can delete that replyMadhivananFailing to plan is Planning to fail |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-09-27 : 22:19:43
|
Darn, I was going to suggest you were joining on the wrong column.Please remove this post.where tableb.fid is tablea.id,,,SELECT a.name,b.fid,b.cfid AS cform_idFROM bJOIN aON a.id = b.cfid CODO ERGO SUM |
 |
|
|
|
|
|
|