dongya2030 2015-12-29 10:29
浏览 84
已采纳

PDO查询使用具有单独参数的两个表

I have two tables. One with login information logins which holds password column and one with emails emails which holds email column and loginID column. I would like to use parameters on both tables. I would like to find row in emails where email=? and then take the corresponding login id inside that row and match this to a row in logins table. I would then like to match the password to the row in logins. A double separated where statement from two tables.

Something along the lines of:

$prepareTables=$listersDatabase->prepare("select*from emails where email=? left join logins on emails.loginID=logins.ID where password=?");
$prepareTables->execute(array("email@email.com","password123"));

Any help is appriciated

  • 写回答

1条回答 默认 最新

  • dongmaopan5738 2015-12-29 10:43
    关注

    Try this:

    SELECT * 
    FROM
        emails 
    INNER JOIN logins 
    ON emails.loginID=logins.ID 
    WHERE 
        emails.email=?
    AND
        password=?
    

    I used INNER JOIN instead of LEFT JOIN as you have this table inside a WHERE condition anyway. You must put all your conditions inside one WHERE clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?