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?

Author  Topic 

codrgiii
Starting Member

29 Posts

Posted - 2009-05-29 : 14:30:05
How am i able to select from a whole column if the result is more than the 1 of the same result?

To break it down a lil, say i wanted to select from table WORK and from column usage, how would i be able to select the results of the usage column if 2 of more results were the same?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-29 : 14:37:17
do you mean this?

SELECT DISTINCT usage FROM WORK
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-05-29 : 15:11:57
Or do you mean you want to find only the duplicates?

select usage, count(*) [occurrence_count]
from work
group by usage
having count(*) > 1

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-30 : 02:30:45
would apprecaite if you could give us some sample data and explain what you want rather than keeping us guessing
Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2009-06-01 : 01:30:01
hi!

what if i want
to show like this

+-------------+-------
|Country |
+-------------+-------
|Phil |
+-------------+-------
|Phil |
+-------------+-------
|USA |
+-------------+-------
|USA |
+-------------+------
|Phil |
+-------------------_
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 01:36:40
have you tried the query TG posted ?


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

Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2009-06-01 : 01:39:52
yup but it shows like this

+-------------+-------
|Country |
+------ ---+-------
|Phil |3
+----------+-------
|USA |2
+----------+-------
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-06-01 : 01:52:16
just inner join back to your original table

select t.Country
from yourtable t
inner join
(
select Country
from yourtble
group by Country
having count(*) > 1
) m on t.Country = m.Country



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

Go to Top of Page
   

- Advertisement -