File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL Select Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Select Help" Watch "SQL Select Help" New topic

SQL Select Help

Richard Murry

Joined: Aug 20, 2007
Posts: 1
Hoping someone can help me out here . . .

I have a table that contains a number of records. It has two fields, "Starter" and "Main Course". Typical data would look like this. . .

Soup, Beef
Soup, Chicken
Salad, Pork
Soup, Beef
Salad, Chicken
Soup, Beef
Salad, Pork
etc . . .

I need to try and select all similar pairs that occur in the table more than once. For example, in the above table, I would be looking to select Soup and Beef and Salad and Pork as they occur more than twice.

Anyone help?
Chad Clites
Ranch Hand

Joined: Aug 16, 2005
Posts: 134
Off the top of my head, something like:
SELECT Starter, Main, Count(Main)AS cnt FROM my_table WHERE cnt>1;
should get you a list of any duplicates.
[ August 29, 2007: Message edited by: Chad Clites ]
It is sorta covered in the JavaRanch Style Guide.
subject: SQL Select Help