0

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?

Uttam Kumar Roy
  • 2,060
  • 4
  • 23
  • 29
Draez
  • 23
  • 5

1 Answers1

0

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,

HarisH Sharma
  • 1,101
  • 1
  • 11
  • 38