here is my query -
SELECT column_one FROM generation1 UNION SELECT column_one FROM generation2 WHERE column_one = value;
I am trying to query both tables for the value and i want PHP to execute a block of code if no result is found but the value in the where condition returns a result even when the value doesn't exist on both tables.
Pls how can I make this query work and return the value of the "where" condition?
CodePudding user response:
I think you want the WHERE
logic to apply to the entire result set generated by the union query. If so, then you should subquery and apply the filter there:
SELECT column_one
FROM
(
SELECT column_one FROM generation1
UNION ALL
SELECT column_one FROM generation2
) t
WHERE column_one = value;