File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQL Query Suggestions

 
Rachel Kumar
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
----------
Rest_id
Rest

Table Ant
---------
Ant_id
Ant_name

Table RestAnt
-------------
Rest_id
Ant_id


1.select 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'

2.select re.rest 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
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrong forum, methinks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33694
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic