gpt4 book ai didi

php - 如何使用 join 5 表从数据库中获取数据

转载 作者:行者123 更新时间:2023-11-30 22:02:31 26 4
gpt4 key购买 nike

示例数据

job_category
**catergory_id** **category_name**
3 Tourism and Travel Services

job
**job_id** **role** **category_id**
1 Financial Accountant 3

exam_paper
**exam_paper_id** **exam_paper_name** **job_id**
1 FA -TTS 1

question
**question_id question option1 option2 option3 option4**
15 AAA a1 a2 a3 a4
38 BBB b1 b2 b3 b4
39 CCC c1 c2 c3 c4
44 DDD d1 d2 d3 d4
45 EEE e1 e2 e3 e4

exam_question_list
**id** **exam_paper_id** **category_id** **job_id** **q1 q2 q3 q4 q5**
1 1 3 1 15 38 39 44 45

我想从exam_question_list表中获取详细信息,预期结果是问题,根据question_paper_list表'q1-q5'从问题表中选择

我尝试获取数据,但它不起作用;

SELECT *
FROM exam_question_list eq
LEFT JOIN exam_paper ex
ON eq.exam_paper_id = ex.exam_paper_id
LEFT JOIN job j
ON j.job_id = ex.job_id
LEFT JOIN job_catergory jc
ON jc.catergory_id = j.catergory_id
LEFT JOIN question q
ON q.question_id=eq.q1

此查询仅给出问题 1。我想得到所有 5 个问题。如何做?

最佳答案

您的查询是错误的。正确的是

SELECT eq.*
FROM exam_question_list eq
LEFT JOIN exam_paper ex ON eq.exam_paper_id = ex.exam_paper_id
LEFT JOIN job j ON j.job_id = ex.job_id
LEFT JOIN job_catergory jc ON jc.catergory_id = j.catergory_id
LEFT JOIN question q ON q.question_id=eq.q1

关于php - 如何使用 join 5 表从数据库中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42942967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com