| Author |
Topic |
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2009-10-01 : 10:25:00
|
| I need to select the top 3 distinct from the below stored procedure rather than the top 3, how do I do this?SELECT top 3 tb_specialoffer.*, dbo.tb_properties.*, tb_counties.*, tb_regions.*, tb_country.*, tb_town.*, tb_photos.* FROM tb_specialoffer INNER JOINdbo.tb_properties ON dbo.TB_specialoffer.so_bnbid = dbo.tb_properties.PropertyID INNER JOINdbo.tb_counties ON dbo.tb_properties.Prop_County = dbo.tb_counties.county_id INNER JOINdbo.tb_regions ON dbo.tb_counties.region_id = dbo.tb_regions.RegionID INNER JOINdbo.tb_country ON dbo.tb_regions.Region_Country = dbo.tb_country.CountryID INNER JOINdbo.tb_photos ON dbo.tb_properties.PropertyID = dbo.tb_photos.propertyid INNER JOINtb_town ON tb_town.town_id = prop_townWHERE dbo.tb_photos.main_photo = 1 AND town_approved = 1 and tb_properties.prop_visible = 1 and tb_specialoffer.so_start <current_timestamp and tb_specialoffer.so_end > current_timestamp |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-10-01 : 10:56:11
|
| SELECT TOP 3 FROM (SELECT DISTINCT ...FROM...WHERE...) A ORDER BY ... |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-10-01 : 14:54:58
|
unambiguously distinct *,*,*,*,*,*,* No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-01 : 14:55:35
|
| you mean distinct of entire value combination or distinct of any 1 field? |
 |
|
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2009-10-02 : 04:35:12
|
| Sorry I should have been more clearer.I need to find a distinct value of tb_properties.propertyid. All methods I tried I end up with unambiguously distinct |
 |
|
|
godspeedba
Yak Posting Veteran
90 Posts |
Posted - 2009-10-02 : 04:35:52
|
| Posted - 10/02/2009 : 04:35:12 -------------------------------------------------------------------------------- Sorry I should have been more clearer.I need to find the top 3 distinct value of tb_properties.propertyid. All methods I tried I end up with unambiguously distinct |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-02 : 06:21:09
|
quote: Originally posted by godspeedba Sorry I should have been more clearer.I need to find a distinct value of tb_properties.propertyid. All methods I tried I end up with unambiguously distinct
then you should decide what values you need to bring along with this distinct propertyid from other fields. you need to apply some aggregation like min,max,sum,... for others |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-10-02 : 11:23:04
|
| SELECT DISTINCT tb_properties.propertyidFROM tb_specialoffer INNER JOINdbo.tb_properties ON dbo.TB_specialoffer.so_bnbid = dbo.tb_properties.PropertyID INNER JOINdbo.tb_counties ON dbo.tb_properties.Prop_County = dbo.tb_counties.county_id INNER JOINdbo.tb_regions ON dbo.tb_counties.region_id = dbo.tb_regions.RegionID INNER JOINdbo.tb_country ON dbo.tb_regions.Region_Country = dbo.tb_country.CountryID INNER JOINdbo.tb_photos ON dbo.tb_properties.PropertyID = dbo.tb_photos.propertyid INNER JOINtb_town ON tb_town.town_id = prop_townWHERE dbo.tb_photos.main_photo = 1 AND town_approved = 1 and tb_properties.prop_visible = 1 and tb_specialoffer.so_start <current_timestamp and tb_specialoffer.so_end > current_timestampBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|