How do I join on same column for different values and both the values should be and
condition?
eg: TABLEA.COLUMNA='XYZ' AND TABLEB.COLUMNA='PQR'
Please note TableA
and TableB
are same table.
How do I join on same column for different values and both the values should be and
condition?
eg: TABLEA.COLUMNA='XYZ' AND TABLEB.COLUMNA='PQR'
Please note TableA
and TableB
are same table.
From your tagging you know need a self-join, in which two instances of the table are joined to each other. That's as simple as you would hope it would be:
select a.id as a_id
, b.id as b_id
from your_table a
cross join your_table b
where a.columnA = 'XYZ'
and b.columnA = 'PQR'
This query doesn't make sense logically. The cross join will produce a product of all the permutations of a.id, b.id
. You probably don't want that. Maybe you want something like this:
select a.id as a_id
, b.id as b_id
from your_table a
join your_table b
on a.some_other_column = b.some_other_column
where a.columnA = 'XYZ'
and b.columnA = 'PQR'
But you didn't post all your criteria so only you know for sure.