how to intersect two "selects" and then put another condition for the result
I want to intersect two "select" queries and then put another condition for the wh开发者_如何学运维ole result. I mean:
(select ... intersect select ...) where ...
is it possible?
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>
Select * From (select ... intersect select ...) as intersectedTable where ...
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;
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)
精彩评论