我有两个表,categories
表构成了类别ID号和类别标题之间的关系。 category_has_child
表格构成categories
表格中的父/子关系。
示例数据:
categories
+---------------+
| id | title |
+----+----------+
| 1 | Tops |
+----+----------+
| 2 | T-Shirts |
+----+----------+
| 3 | Hoodies |
+----+----------+
| 4 | Bottoms |
+----+----------+
| 5 | Shorts |
+----+----------+
| 6 | Pants |
+----+----------+
| 7 | Sale |
+----+----------+
| 8 | Summer |
+----+----------+
category_has_child
+--------------------+
| parent | child |
+----------+---------+
| 1 | 2 |
+----------+---------+
| 1 | 3 |
+----------+---------+
| 4 | 5 |
+----------+---------+
| 4 | 6 |
+----------+---------+
| 7 | 1 |
+----------+---------+
| 7 | 4 |
+----------+---------+
| 8 | 5 |
+----------+---------+
这是将多维数组存储到表中的最有效方法吗?无论如何,我只能用SQL脚本来查询这个问题而没有很多LEFT JOIN
s?