Search code examples
mysqlambiguityfully-qualified-naming

Select from multiple tables with same condition, avoid ambiguity error


How can I do something like this but avoid the error column common_reference is ambiguous? I know it's ambiguous, I want to select from table_one all the results for common_reference there, and table_two the same.

SELECT * FROM table_one, table_two WHERE common_reference = 42

This is obviously not going to work, so how do I use subqueries to achieve what I need?


Solution

  • As suggested by Mchl in the comments UNION was the solution.