exp table: This is where I store entries while keeping the domains and sub domains in a separate table. The sub_domain
column can have one or multiple ids that match the id
column in misc
.
+----+---------+-----------+------------+-----------+--------+-------------+------------+------------+
| 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 |
+----+---------+-----------+------------+-----------+--------+-------------+------------+------------+
misc table:
+-----+----------------------------------------+--------------+
| id | name | category |
+-----+----------------------------------------+--------------+
| 89 | Name1 | category |
| 91 | Name2 | category |
| 93 | Name3 | category |
| 95 | Name4 | category |
| 55 | Name5 | category |
I was wondering how to change LEFT JOIN misc c ON a.sub_domain=c.id
if there are more than one sub_domains in the exp table while keeping in mind that there can be one id as well.
$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 = ?";