This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript 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.
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!