Select * from TABLE_A aa where Exists (Select ab.id From table_b ab And 
ab.data_b = 100 And aa.id = ab.id)

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of [email protected]
Sent: Monday, December 16, 2013 12:41 PM
To: [email protected]
Subject: [firebird-support] get data from table based on criteria from another 
table

 

  

Hi,

I have two tables, TABLE_A and TABLE_B

TABLE_A:
------
ID: INT
DATA_A: INT

TABLE_A data:
(ID, DATA_A)
1, 11
2, 12
3, 13
4, 14
9, 19

TABLE_B:
------
ID: INT
DATA_B: INT

TABLE_B data:
(ID, DATA_B)
1, 100
2, 200
3, 200
5, 100
7, 300
9, 100

I want to do the following: get all records from TABLE_A, for which ID exists 
in TABLE_B and DATA_B for that ID equals 100. Or in other words:
(1).from tableB, get all ID's for which DATA_B = 100 (here - 1,5,9), and then
(2).get all the records from TABLE_A containing an ID from(1)
In the above case, the desired result would be 
1, 11
9, 19

Hope I explained it well. 
Thanks for any suggestions.

Peter



Reply via email to