Предположим, у меня есть три стола
экипаж
+------------+----------+-------------------------+
| EmployeeID | FlightNo | DepartureTime |
+------------+----------+-------------------------+
| 2 | AA123 | 2018-12-30 09:30:45 |
| 7 | AA123 | 2018-12-30 09:30:45 |
| 8 | AA123 | 2018-12-30 09:30:45 |
тип сотрудников
+----------------+-----------------+
| EmployeeTypeID | Name |
+----------------+-----------------+
| 1 | Pilot |
| 2 | First Officer |
| 3 | Stewardess |
и сотрудник
+------------+-----------+----------------+
| EmployeeID | Name | EmployeeTypeID |
+------------+-----------+----------------+
| 2 | James | 2 |
| 3 | Alexandra | 3 |
| 4 | Alina | 2 |
| 6 | Peter | 2 |
| 7 | NULL | 3 |
| 8 | John | 1 |
| 9 | Frank | 1 |
Я присоединился к этим тремтаблицы, но для EmployeeID 7, где имя равно NULL, я не получаю значение NULL, используя левое соединение
select crew.FlightNo, group_concat(distinct(crew.DepartureDateAndTimeUTC) separator ',') as time, group_concat(employee.Name separator ',') as crew,group_concat(distinct(employeetype.Name)separator ',') as type
from employee
left join crew on employee.EmployeeID = crew.EmployeeID
inner join employeetype
on employeetype.EmployeeTypeID = employee.EmployeeTypeID group by crew.FlightNo;
Но я не получаю значение NULL в столбце экипажа
+----------+---------------------+---------------------------------+----------------------------------+
| FlightNo | time | crew | type |
+----------+---------------------+---------------------------------+----------------------------------+
| AA123 | 2018-12-30 09:30:45 | James,John | Pilot,First Officer, Stewardess |
Я хочу в колонке экипажа Джеймс, Джон, NULL