I’m using the following to get data from database in a php file:
$query_pedVR = sprintf("SELECT * FROM tablename WHERE active = 1 ORDER BY name ASC");
What I need to do is combine two tables in one query but can’t seem to get it to work. I have tried the UNION ALL, but can’t find the syntax that works. This isn’t working:
$query_pedVR = sprintf("SELECT * FROM table1 UNION ALL SELECT * FROM table2 WHERE active = 1 ORDER BY name ASC");
Also tried:
$query_pedVR = sprintf("SELECT * FROM table1 WHERE active = 1 ORDER BY name ASC UNION ALL SELECT * FROM table2");
There are not any common entries in the two tables. The two tables also have a different set of columns.
Is it possible to do this with different table structures?
Thanks for any help you can offer.
If tables have different structure you can’t use
select *but you must specify single fields