Merging 2 tables with similar column name SAP HANA database

This can be done by using UNION or UNION ALL operator. Both operators allow you to combine rows from two or more tables that have similar column structures.

Using UNION Operator

The UNION operator combines the result sets of two SELECT statements and removes duplicate rows ?

SELECT id, Empl_name, DeptId FROM table1
UNION
SELECT id, Empl_name, DeptId FROM table2;

Using UNION ALL Operator

The UNION ALL operator combines the result sets and includes all rows, including duplicates ?

SELECT id, Empl_name, DeptId FROM table1
UNION ALL
SELECT id, Empl_name, DeptId FROM table2;

Key Differences

The main difference between UNION and UNION ALL is that:

  • UNION removes duplicate rows from the combined result set
  • UNION ALL preserves all rows, including duplicates

Important Requirements

When merging tables using these operators, ensure that ?

  • Both tables have the same number of columns in the SELECT statements
  • Corresponding columns have compatible data types
  • Column order matches between the SELECT statements

Conclusion

UNION and UNION ALL operators provide efficient ways to merge data from tables with similar column structures in SAP HANA, with UNION removing duplicates and UNION ALL preserving all rows.

Updated on: 2026-03-13T18:21:15+05:30

620 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements