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 |
JeffS23
Posting Yak Master
212 Posts |
Posted - 2008-01-03 : 21:06:12
|
I would like to select data from a database using 'Select * " based on a value in a row (same column)being unique.By that I mean that that data must not repeat again. Idealy I would like to set the number my self so rather then unique I could say select the rows from the database only if the uniquevalue does not repeat more then x number of times.egValue AValue BValue CValue BValue BValue CSo if I wanted to set the uniquness to 1 then only row with Value A would be collected.If I set the uniquenss to =<2 then I would get data from rows with value A and C so 3 rows returned.I have this so farSELECT *FROM SingleS.mdbGROUP BY UniquevalueHAVING count(*) = 1 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-03 : 21:09:50
|
[code]SELECT UniquevalueFROM SingleS.mdbGROUP BY UniquevalueHAVING count(*) = 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
JeffS23
Posting Yak Master
212 Posts |
Posted - 2008-01-03 : 21:28:18
|
Its close and does exactly what it says. However it does not return the whole row which is what i need.is there a way to do this? |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-01-03 : 21:42:00
|
[code]SELECT a.*FROM SingleS.mdb a INNER JOIN ( SELECT Uniquevalue FROM SingleS.mdb GROUP BY Uniquevalue HAVING COUNT(*) = 1 ) u ON a.Uniquevalue = u.Uniquevalue[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-04 : 08:48:17
|
[code]SELECT a.*FROM SingleS.mdb t1 INNER JOIN ( SELECT Uniquevalue FROM SingleS.mdb GROUP BY Uniquevalue HAVING COUNT(*) <= n ) t2 ON t2.Uniquevalue = t1.Uniquevalue[/code]here n will be uniqueness number set by user |
 |
|
|
|
|