dongshou7903 2016-04-24 10:17
浏览 28

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

I have two table one is random_questions and another is personal_questions,Ii want to check copy_id column in personal_questions where personal_questions.question_to = current_session_user and personal_question.copy_id = random_question.id....

Here is my code :

$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)");

I am not getting the results properly, if personal_questions's copy_id is equals to any of random_questions's id then results repeats automatically. I hope you understand. Help please.

  • 写回答

1条回答 默认 最新

  • duanfu7840 2016-04-24 10:51
    关注
    Select *
    from   random_questions   p,
           personal_questions a
    where  a.question_to = current_session_user
    and    a.copy_id     = p.id;
    
    评论

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”