I have two tables where similar records stored. I have to search for existing record, where reference value matches one record if record is not found in first table, I need to search second table.
I tried querying like this but it returns all the records
SELECT * FROM keys WHERE EXISTS(SELECT * FROM store_1 WHERE store_1.key_number LIKE '%1726-1726280-17998%') or EXISTS(SELECT * FROM store_2 WHERE store_2.key_number LIKE '%1726-1726280-17998%');
2
Answers
As I understood with union I can return records with same number of columns
You can try this version if you’d not want a UNION of the tables, it combines both conditions into a single SELECT statement like you intended initially.