1,105,556 Community Members

SQL to display duplicate data once

Member Avatar
coder91
Junior Poster in Training
97 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Have a database table with various tasks and each has a time against it that it should take, some tasks have the same time. I now need to display these times in a drop down list but only want to display each time once, how can I do this?

Member Avatar
rch1231
Veteran Poster
1,187 posts since Sep 2009
Reputation Points: 131 [?]
Q&As Helped to Solve: 194 [?]
Skill Endorsements: 13 [?]
 
0
 

Hello,

Try something like this substituting your table and field names:

select table.timefield,
count(table.timefield) AS NumberOf
FROM
table
GROUP BY
table.timefield
HAVING
NumberOf > 1

This should give you only times where there is more than on row and the number of rows.

Member Avatar
coder91
Junior Poster in Training
97 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

After I posted I realised I could alter the stored proc and use DISTINCT, hopefully this works. Thank you though, if DISTINCT doesn't work I'll try your way :)

Member Avatar
rch1231
Veteran Poster
1,187 posts since Sep 2009
Reputation Points: 131 [?]
Q&As Helped to Solve: 194 [?]
Skill Endorsements: 13 [?]
 
0
 

Distinct will work perfectly. I read your request as wanting only times where ther were duplicates. Also look at group by for some options.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article