aspose file tools*
The moose likes JDBC and the fly likes print only the duplicate values in sql. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "print only the duplicate values in sql. " Watch "print only the duplicate values in sql. " New topic
Author

print only the duplicate values in sql.

bhavin ragha
Greenhorn

Joined: Mar 28, 2012
Posts: 17
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

Joined: Mar 28, 2012
Posts: 859

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

Joined: Mar 28, 2012
Posts: 17
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

Joined: Aug 22, 2010
Posts: 3610
    
  60

Move the order by clause to the end of the statement. Order by must always go last.
 
 
subject: print only the duplicate values in sql.