P粉5390555262023-08-11 10:16:00
To search within a fixed set of tables, you can combine individual queries using the UNION
clause and then add a hardcoded string to identify the source:
SELECT packaging_id AS product_id, 'packaging' AS table_name FROM packaging WHERE name = 'Cardboard box' UNION ALL SELECT stationery_id, 'stationery' FROM stationery WHERE description = 'Cardboard box' UNION ALL SELECT sales_id, 'sales' FROM sales WHERE offer = 'Cardboard box'
You need to ensure that each column in the result set has the same data type, and you can use the first statement to set a normalized column name for the result set.