aspose file tools*
The moose likes JDBC 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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Select Help" Watch "SQL Select Help" New topic
Author

SQL Select Help

Richard Murry
Greenhorn

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. . .

Starter�Main
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 ]
 
Consider Paul's rocket mass heater.
 
subject: SQL Select Help