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
 how to select only the unique(not distinct) rows

Author  Topic 

pritesh1908
Starting Member

4 Posts

Posted - 2012-03-28 : 10:45:23
how do i fetch only the unique tuples based on a particular atttribute
for e.g

name movie yr
amit yoyo 2011
prit hoho 2010
jeet gogo 2011
ajay jojo 2015
jeet koko 2018
ajay lolo 2011

we want only the tuples with unique yr
i.e.
prit hoho 2010
ajay jojo 2015
jeet koko 2015

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-28 : 10:57:46
[code]
select *
from yourtable t
inner join
(
select yr
from yourtable
group by yr
having count(*) = 1
) m on t.yr = m.yr
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-28 : 11:04:04
Do you mean

prit hoho 2010
ajay jojo 2015
jeet koko 2018

???

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

pritesh1908
Starting Member

4 Posts

Posted - 2012-03-28 : 12:05:45
thanx a lot khtan..that worked
Go to Top of Page
   

- Advertisement -