我试图写一个SQL
语句,可以在PHP
中用于网站,但我无法理解如何访问这些信息。
我有以下表格..
请注意: ACADEMIC_ID
& STUDENT_ID
只是USER_ID
的外键。
当我试图访问PHP
中网站学生视图中的信息时,我只能使用以下信息。
USER_ID
。 DEBATE_ID
。因此..
可以使用哪种SQL语句来提供所需的结果?
答案 0 :(得分:0)
SELECT A.TITLE
, B.TITLE
, C.FIRSTNAME
, C.LASTNAME
, D.DATE_CREATED
FROM STARTER_PACT A
, UNITS B
, USERS C
, DEBATE D
, DEBATE_GROUPS E
WHERE A.ACADEMIC_ID = C.ID
AND B.ACADEMIC_ID = C.ID
AND D.ID = E.DEBATE_ID
AND E.STUDENT_ID = C.ID
AND C.ID = "(USER_ID)"
AND D.ID = "(DEBATE_ID)"
答案 1 :(得分:0)
如果您只有2个信息(user.id和debate.id),则使用内部联接,该流程来自debates_group - >辩论 - > starter_packs(来自debates.starter_pack_id的连接) - > units(starter_packs.academic_id) - >用户(stater_packs.academic_id)
SELECT STARTER_PACKS.TITLE, UNITS.TITLE, USERS.FIRSTNAME, USERS.LASTNAME, DEBATE.DATE_CREATED FROM DEBATES_GROUP
INNER JOIN DEBATES ON DEBATES_GROUP.DEBATE_ID = DEBATES.ID
INNER JOIN STARTER_PACKS ON STARTER_PACKS.ID = DEBATES.STARTER_PACK_ID
INNER JOIN UNITS ON STARTER_PACKS.ACADEMIC_IC = UNITS.ACADEMIC_ID
INNER JOIN USERS ON UNITS.ACADEMIC_ID = USERS.ID
WHERE DEBATES_GROUPS.DEBATE_ID = ? AND DEBATES_GROUPS.STUDENT_ID = ?
希望这有效