我有两个表一个是random_questions,另一个是personal_questions,我想检查个人事项中的copy_id列personal_questions.question_to = current_session_user
和personal_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,则结果会自动重复。我希望你明白。请帮忙。
答案 0 :(得分:0)
Select *
from random_questions p,
personal_questions a
where a.question_to = current_session_user
and a.copy_id = p.id;