私には、人、属性、および属性の潜在的な値を含む3つのテーブルがあります。すべての人、各人の属性、およびそれらの欠落/null属性を表示するクエリを理解できません。
これがテーブルの例です...
attributes
+---------------------+
| attribute_name (col)|
+---------------------+
| name |
+---------------------+
| age |
+---------------------+
| gender |
+---------------------+
| email |
+---------------------+
people
+-----------+----------+
| person_id | value_id |
+-----------+----------+
| 2 | 7 |
+-----------+----------+
| 2 | 9 |
+-----------+----------+
| 3 | 8 |
+-----------+----------+
values
+---------------+----------------+-------+
| value_id (pk) | attribute_name | value |
+---------------+----------------+-------+
| 7 | age | 35 |
+---------------+----------------+-------+
| 8 | age | 28 |
+---------------+----------------+-------+
| 9 | gender | male |
+---------------+----------------+-------+
3つのテーブルを結合して、このようなものを表示するにはどうすればよいですか?
+-----------+----------+-----------------+--------+
| person_id | value_id | attribute_name | value |
+-----------+----------+-----------------+--------+
| 2 | 7 | age | 35 |
+-----------+----------+-----------------+--------+
| 2 | 9 | gender | male |
+-----------+----------+-----------------+--------+
| 2 | NULL | name | NULL |
+-----------+----------+-----------------+--------+
| 2 | NULL | email | NULL |
+-----------+----------+-----------------+--------+
| 3 | 8 | age | 28 |
+-----------+----------+-----------------+--------+
| 3 | NULL | gender | NULL |
+-----------+----------+-----------------+--------+
| 3 | NULL | name | NULL |
+-----------+----------+-----------------+--------+
| 3 | NULL | email | NULL |
+-----------+----------+-----------------+--------+