Merge Rows in DB2: Complete Guide
In DB2, you can merge multiple rows of data into one using aggregate functions and the GROUP BY clause in SQL. Here is an example:
Suppose there is a table named employee, with columns employee_id, department_id, and salary.
You can use the following SQL query to consolidate the salaries of employees with the same department_id into one record:
SELECT department_id, SUM(salary) AS total_salary
FROM employee
GROUP BY department_id
This will return a result set with the total salary for each department displayed as a single record.