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
 Need Help,\.

Author  Topic 

abcxyz23
Starting Member

2 Posts

Posted - 2013-07-28 : 09:58:49
I have created groups of photos, i want to select one photo from each group, what willbe the query? please help me , its urgent.

aaaa

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-07-28 : 11:06:29
Refer this post http://beyondrelational.com/modules/2/blogs/70/posts/10845/return-top-n-rows.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-28 : 11:35:52
use logic based on ROW_NUMBER as in the link. The partition by should contain your grouped columns and order by should include columns based on which you need to do the ordering. if random order is enough, use NEWID() function.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -