简体   繁体   中英

Combining 2 select statements together in one query

I need to combine 2 select statements together but i get an error:

Notice: Trying to get property of non-object

My code currently:

$sql = "(SELECT id, sijainti FROM sijainti
  UNION ALL
SELECT numero FROM tiedot)";

My code works perfectly otherwise if i try to do this only with one select statement. Any suggestions for making this work?

If you use UNION then number of fetched column must be equal, also name of columns must be same, so modify your query like,

$sql = "(SELECT id AS id, sijainti AS name FROM sijainti UNION ALL SELECT 0 as id, numero AS name FROM tiedot)";

may be it will help you,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM