I'm doing a UNION ALL
to get the results as shows in the table below. This approach is causing to have unnecessary rows. The three columns DESK, SEGMENT and SUPERVISOR are independent and have no relationship.
Code
SELECT ID, DESK, '' as SEGMENT, '' as SUPERVISOR FROM myTable1
UNION ALL
SELECT ID, '' AS DESK, SEGMENT, '' as SUPERVISOR FROM myTable2
UNION ALL
SELECT ID, '' AS DESK, '' as SEGMENT, SUPERVISOR FROM myTable3
Result:
+------+------------+---------+------------+
| ID | DESK | SEGMENT | SUPERVISOR | TOTAL ENTRIES
+------+------------+---------+------------+
| 4782 | OIL & GAS | | | 23
+------+------------+---------+------------+
| 4782 | AUTOMOTIVE | | | 23
+------+------------+---------+------------+
| 4782 | | GLOBAL | | 23
+------+------------+---------+------------+
| 4782 | | | DANIEL | 23
+------+------------+---------+------------+
| 4782 | | | JAMES | 23
+------+------------+---------+------------+
How can I query to get the below result?
Expected Result:
+------+------------+---------+------------+
| ID | DESK | SEGMENT | SUPERVISOR | TOTAL ENTRIES
+------+------------+---------+------------+
| 4782 | OIL & GAS | GLOBAL | DANIEL | 23
+------+------------+---------+------------+
| 4782 | AUTOMOTIVE | | JAMES | 23
+------+------------+---------+------------+