4
select 1 as a,4 as b, 5 as c;
select 1 as a,3 as b;

Result display only of `select 1 as a,3 as b;

How display result of multi select in PgAdmin III?`

D T
  • 141

1 Answers1

3

One way around this limitation would be UNION ALL.

However, the row type of all SELECTs has has to match. So I added NULL for the missing column c in the second query. Could be any value that fits the data type:

SELECT 1 AS a, 4 AS b, 5 AS c FROM tbl_a
UNION ALL
SELECT 1     , 3     , NULL   FROM tbl_b;  -- aliases only needed in 1st SELECT

Returns a single result set.

To indicate the source of each row you could add a column or slide in a row between individual SELECTs. Demonstrating both at once with VALUES expressions:

SELECT * FROM (
   VALUES
      (1, 1, 14, 15)
     ,(1, 2, 17, 11)
   ) AS t(query, a, b, c)

UNION ALL VALUES (NULL::int, NULL::int, NULL::int, NULL::int) -- delimiter

UNION ALL (
   VALUES
      (2, 3, 24, NULL::int)
     ,(2, 4, 27, NULL::int)
   );

Explicit type casts may be necessary. I only added what's absolutely necessary here. ->SQLfiddle demo.