I need to determine if a user supplied value exists in 2 different MySQL tables, and which table it exists in. I know I could do:
SELECT 1 FROM table1 WHERE col_name_table1 = user_value;
And if the user value does not exist there, then I could just check the next table:
SELECT 1 FROM table2 WHERE col_name_table2 = user_value;
In my PHP logic, which executes the SQL queries above, I can easily capture which table the user value exists in depending on the values returned from the queries (i.e. 0, 1).
I'm wondering though, is there a more elegant way to do what I need?
Is it possible to write a single query that checks both tables, and then returns the table where the user value is found?