Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print only the duplicate values in sql.

 
bhavin ragha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a method that will allow me to print only the duplicate values

here in a column
--------
1
1
2
3
3

the out put would be
---------
1
3





 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Native sql, you could execute this in a Java method ...

select colname from tablename
order by colname
group by colname having count(*) > 1;


Try it ...
Then understand what the "group by" and "having" do

Pat.
 
bhavin ragha
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i put this in and it did not work for me. it says "near "group": syntax error"

select releases.cd_id from releases
order by releases.cd_id
group by releases.cd_id
having count(*) > 1

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the order by clause to the end of the statement. Order by must always go last.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic