I have a WebSQL database which has three tables which all contain id’s and PREFIX_name fields. I need to get all the name fields for single id.
Currently I’m trying following clause:
SELECT A_name FROM TableA WHERE companyId = 1 UNION ALL
SELECT B_name FROM TableB WHERE companyId = 1 UNION ALL
SELECT C_name FROM TableC WHERE companyId = 1
This returns the results object as expected but the field names are wrong:
[{
"A_name" : "result from TableA",
},
"A_name" : "result from TableB",
},
"A_name" : "result from TableC"
}];
As you can see, I can’t identify from which table fields are from.
When you
UNIONresults together, the column takes the name given to it in the first query (in this caseA_name)Instead of using
UNION ALL, try joining your tables together:This will give you the results on a single row. If you really want the results as seperate rows, you could perhaps select the table name along with the *_name field: