2
我有4個表,它們分別是:寫有多個MySQL的語句連接
job, community, state, and region.
其結構如下:
job:
columns:
id
community_id
relations:
community: local_key: community_id, foreign_key: id
community:
columns:
id
state_id
relations:
state: local_key: state_id, foreign_key: id
state:
columns:
id
name
region_id
relations:
region: local_key: region_id, foreign_key: id
region:
columns:
id
name
現在,我需要一個查詢,將:
get all the jobs with matching communities: i.e.: j.community_id = c.id
then, from those matches, get all of the jobs in communities with a state region_id = "1"
我做得很好,拉着狀態,但我陷入了試圖拉動該地區。我得到了這個:
SELECT j.id
FROM job j
INNER JOIN community c
ON j.community_id = c.id
WHERE c.state_id = 35
我甚至不知道如果我的表設置正確,以檢索此信息。任何幫助讓我越過駝峯將不勝感激。
就是這樣!非常感謝! – Patrick 2011-12-22 18:38:06
很高興爲你工作,在清晰的數據庫結構的問題+1 – MrCode 2011-12-22 18:49:17