提取數據因此,從我原來的問題有幫助的反饋後,我現在有這個疑問:需要MySQL查詢從兩個表中
SELECT sessions.id, sessions.title, sessions.abstract, sessions.presenters, sessions.proposal_id, proposals.outcomes, proposals.CategorySelection, proposals.research3, proposals.research4, proposals.research5, proposals.research6, proposals.innovation3, proposals.innovation4, proposals.innovation5,proposals.innovation6, proposals.application3, proposals.application4, proposals.application5, proposals.application6, proposals.integration3, proposals.integration4, proposals.integration5, proposals.integration6, proposals.references, proposals.organization
FROM sessions, proposals
INNER JOIN proposals ON proposals.id = sessions.proposal_id
WHERE sessions.id = '$id
LIMIT 1;)
是讓我無處可去快。我究竟做錯了什麼?
原題: 我需要從一個表拉幾個字段,並從第二個表幾聲。條件是名爲proposal_id的字段與第二個表的id字段匹配。我相當新,所以這是我迄今爲止。它不工作,但不知道如何使其工作。
(SELECT `title`,`abstract`,`presenters`,`proposal_id` FROM `sessions` WHERE `id`='$id')
UNION
(SELECT `outcomes`,`CategorySelection`,`research3`,`research4`,`research5`,`research6`,`innovation3`,`innovation4`,`innovation5`,
`innovation6`,`application3`,`application4`,`application5`,`application6`,`integration3`,`integration4`,`integration5`,`integration6`,`references`,`organization` FROM `proposals` WHERE `id`= `sessions`.`proposal_id`)
LIMIT 1;
http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ – Mihai
我希望我能給你們兩個答案。非常感謝!那正是我需要的! –
問題原來是別的,所以標記這個答案。 –