I am using java/oracle. i have below issue.
SELECT
DISTINCT id_one,
status
FROM
sometable
WHERE
id_two IN (
SELECT
DISTINCT id_two
FROM
othertable
)
AND id_one IN (1946,1948,1949)
i have above query to fetch data from one table. inner query’s data from other table.
now i need add one where condition to inner query.
othertable has one more field called name.
these are the ids that i mentioned: 1946,1948,1949. here each id will have names as below: name1, name2, name3
name1, name2, name3 are passed from java application.
finally the query that i need as follows.
SELECT
DISTINCT id_one,
status
FROM
sometable
WHERE
id_two IN (
SELECT
DISTINCT id_two
FROM
othertable other where other.name in('name1','name2','name3')
)
AND id_one IN (1946,1948,1949)
my questions is: for 1946 id name1 should be considered and for 1948 id name2 should be considered
*and for 1949 id name3 should be considered as criteria.* i mean query should not consider all 3 names for every id.
how can i achieve it?
This can also be done like in the following way: