I want to intersect two "select" queries and then put another condition for the whole result. I mean:
(select ... intersect select ...) where ...
is it possible?
I want to intersect two "select" queries and then put another condition for the whole result. I mean:
(select ... intersect select ...) where ...
is it possible?
Select * From (select ... intersect select ...) as intersectedTable where ...
Depends on your flavour of database Oracle (for example) will allow this:
SELECT *
FROM ( SELECT *
FROM TABLE_A
INTERSECT
SELECT *
FROM TABLE_B
)
WHERE <conditions>
Since you are intersecting, any condition you put on the either of the two SELECTs will also apply to the whole condition...
So, the easiest way is to just
SELECT ... FROM ... WHERE (condition)
INTERSECT
SELECT ... FROM ... WHERE (another condition)
You want to use a derived table.
SELECT value,data FROM
(SELECT value,data FROM table1 union select value,data from table2) t
WHERE value=5;