gpt4 book ai didi

php - 如何准备查询以从另一个表检查然后从另一个表获取

转载 作者:行者123 更新时间:2023-11-29 21:05:59 26 4
gpt4 key购买 nike

我有两个表,一个是random_questions,另一个是personal_questions,我想检查personal_questions中的copy_id列,其中personal_questions.question_to = current_session_userpersonal_question.copy_id = random_question.id....

这是我的代码:

$session_user = $_SESSION['user_id'];

$sql = mysqli_query($con, "SELECT DISTINCT random_questions.id AS id, random_questions.question_by_id AS question_by_id, random_questions.question AS question, random_questions.total_answers AS answers FROM random_questions INNER JOIN personal_questions WHERE (random_questions.total_answers != '8') OR (personal_questions.question_to != '$session_user' AND personal_questions.copy_id != random_questions.id)");

我没有正确得到结果,如果personal_questions的copy_id等于任何random_questions的id,那么结果会自动重复。我希望你明白。请帮助。

最佳答案

Select *
from random_questions p,
personal_questions a
where a.question_to = current_session_user
and a.copy_id = p.id;

关于php - 如何准备查询以从另一个表检查然后从另一个表获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36821836/

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