Home > OS >  How to get the gap in result from union all in tables?
How to get the gap in result from union all in tables?

Time:03-30

select id,name from t1
id  name
1   A
2   B
select id,name,sal from t2
id name sal
1   C   1000
2   D   2000
select id,name,Null as sal from t1 
UNION ALL
select id,name,sal from t2
id  name sal
1   A
2   B
1   C   1000
2   D   2000

But I need like this

id  name sal
1   A
2   B

1   C   1000
2   D   2000

There should be some gap required between two results

CodePudding user response:

This is more like a reporting type of query since you are asking about formatting of the data layout rather than the content itself. You can somehow tweak the result using:

select id, name, sal
from (
  select 1 as section, id, name, null as sal from t1 
  UNION ALL
  select 2, null, null, null
  UNION ALL
  select 3, id, name, sal from t2
) x
order by section

However, it's worth to point out that formatting is better done in the UI rather than at the database level. At the UI you have access to fonts, colors, borders, bold, italics, underline, etc.

  • Related