'Getting one single table from 3 tables where 2 of the tables have the same column
I have the following three tables in my sql
+------+--------+------+------------+
| id | letter | date | identifier |
+------+--------+------+------------+
| 1 | a | mar | 100 |
+------+--------+------+------------+
+------+--------+------+------------+
| id | letter | date | identifier |
+------+--------+------+------------+
| 1 | a | mar | 100 |
+------+--------+------+------------+
+------+--------+------+------------+
| id | letter | date | identifier |
+------+--------+------+------------+
| 10 | b | mar | 200 |
| 10 | c | feb | 300 |
+------+--------+------+------------+
the goal here is to combine the two tables based on the dates
+------+------+--------+--------+------+
| ida | idb | letter | letter | date |
+------+------+--------+--------+------+
| 1 | 10 | a | b | mar |
| 1 | 10 | null | c | feb |
+------+------+--------+--------+------+
I have the following query below
select ida, idb, table2.letter, table3.letter, table2.date, table3.date
from table2
left join table1 A
on A.ida = table2.id
left join table3
on A.idb = table3.id group by table2.date;
but the result is the following
+------+------+--------+--------+------+------+
| ida | idb | letter | letter | date | date |
+------+------+--------+--------+------+------+
| 1 | 10 | a | b | mar | mar |
+------+------+--------+--------+------+------+
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
