This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes SQL Query Suggestions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Query Suggestions" Watch "SQL Query Suggestions" New topic

SQL Query Suggestions

Rachel Kumar
Ranch Hand

Joined: Oct 21, 2008
Posts: 51
I have 3 tables as shown below.

i want to retrieve all the 'Rest' that has 'Ant_id = 1 and 2 and 3 and 4 so on'...

i tried the below queries...din work

suggestions please!

Table Rest

Table Ant

Table RestAnt
Ant_id rest from rest where rest_id in ( select rest_id from restant where ant_id in ( 1,2,3 ) );
- this is equivalent to an 'OR' from rest re, restant ra where ra.rest_id = re.rest_id and ant_id = 1 and ant_id = 2;
- this did not work
David Newton

Joined: Sep 29, 2008
Posts: 12617

Wrong forum, methinks.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32319

ant_id = 1 and ant_id = 2;

This is impossible. Ant_id will never be both 1 and 2 for the same record. The following two do what you want:

ant_id in (1, 2);
ant_id = 1 or ant_id = 2;

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
I agree. Here's the link:
subject: SQL Query Suggestions
jQuery in Action, 3rd edition