我有3个表,名称分别为city
,state
和project
城市
id_city | name_city
1 | JED
2 | RYD
3 | DMM
状态
带有city.city_id的列city_id外键
id_state | name_state | city_id
1 | JED 1 | 1(JED)
2 | RYD 1 | 2(RYD)
3 | RYD 2 | 2(RYD)
项目
状态为.city_id的列state_from_city_id_table_state外键
id_project | city_id | state_from_city_id_table_state
1 | 1 | 1(JED)>> (JED1) question here
2 | 2 | 2(RYD)>> (RYD 1 or2) question here
现在我选择的问题是city_id from project table
...像1一样,我只想在city_id from state table number 1 without number 2
中看到state_id from table project
像JED > JED1 only i don't wanna see RYD1 and RYD2
答案 0 :(得分:-1)
SELECT ct.*, st.*, pr.* FROM `city` ct LEFT JOIN `state` st ON ct.`id_city` = st.`state_id` LEFT JOIN `project` pr ON ct.`id_city` = pr.`city_id`