exp表:這是我存儲條目的位置,同時將域和子域保留在單獨的表中。 sub_domain
列可以有一個或多個與misc
中的id
列匹配的ID。多個ID的聯接表
+----+---------+-----------+------------+-----------+--------+-------------+------------+------------+
| id | user_id | job_type | experience | exp_title | domain | sub_domain | start | end |
+----+---------+-----------+------------+-----------+--------+-------------+------------+------------+
| 83 | 268 | Full Time | dasdfg | dest | 76 | 89,91,93,95 | 07/15/2012 | 07/31/2012 |
| 84 | 269 | Full Time | abcdef | title | 77 | 89 | 07/15/2011 | 07/31/2011 |
+----+---------+-----------+------------+-----------+--------+-------------+------------+------------+
雜項表:
+-----+----------------------------------------+--------------+
| id | name | category |
+-----+----------------------------------------+--------------+
| 89 | Name1 | category |
| 91 | Name2 | category |
| 93 | Name3 | category |
| 95 | Name4 | category |
| 55 | Name5 | category |
我想知道如何改變LEFT JOIN misc c ON a.sub_domain=c.id
如果在使用EXP表中的多個sub_domains同時牢記可以有一個ID爲好。
$query_str = "SELECT a.*, b.name, c.name AS sub_name
FROM exp a
LEFT JOIN misc b ON a.domain=b.id
LEFT JOIN misc c ON a.sub_domain=c.id
WHERE a.user_id = ?";
考慮從[1NF]重組你的表(http://en.wikipedia.org/wiki/First_normal_form)到[2NF](http://en.wikipedia.org/wiki/Second_normal_form)。 – 2012-07-20 10:11:51