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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Duplication issue

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-04-24 : 10:18:18
Hello friends

SELECT top 3 tb_features.feature_id
FROM dbo.TB_Features, tb_properties
WHERE county_display = 1 AND (feature_paid <> 1 or feature_paid is null) and tb_features.property_id = tb_properties.propertyid and tb_properties.prop_county = @thevalue ORDER BY NEWID()

The above seems to duplicate the data numerous times which is really confusing me, what am I doing wrong?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-24 : 10:24:42
It depends on the JOIN.
Try to add a DISTINCT keyword in your query
SELECT TOP 3	tb_features.feature_id
FROM dbo.TB_Features
INNER JOIN tb_properties ON tb_features.property_id = tb_properties.propertyid
WHERE county_display = 1
AND (feature_paid <> 1 or feature_paid is null)
tb_properties.prop_county = @thevalue
ORDER BY NEWID()



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-04-24 : 10:32:00
ah I see now. Thanks very much Peso
Go to Top of Page
   

- Advertisement -