2

E.g. Table 1 Japan Customers

Table 2 USA Sales People

Table 3 HK Engineers


There are selects from the 3 tables each. However, can I run all 3 selects within a single/overall select statement and output 1 result set, so one can see each row labeled based on the table name? all these tables don't have similar columns but share a common id column

Col1 Col2 Col3...

Japan

USA

HK

  • You can merge the result of two or more different queries using UNION ALL, but number of columns and names must match. – McNets Apr 14 '17 at 8:14
1

Is possible to merge/add the result of two or more different queries using:

UNION ALL

But count and names of columns must match on each query.

Of course you can add null or fixed values as needed.

SELECT COL1 AS ID, COL2 AS NAME, NULL AS INFO
FROM   TABLE1
UNION ALL
SELECT F1 AS ID, F2 AS NAME, INFO
FROM.  TABLE2
UNION ALL
SELECT 0 AS ID, NAME, INFO
FROM   TABLE3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.