php - mysql 加入 where 条件的问题

标签 php mysql left-join inner-join

我有两张 table

  Profile                         Status
  profile_id |name | active       status_id |profile_id|age

我需要获取配置文件“活跃”为 1 且状态年龄大于 10 的状态

当 profile_id 匹配时,此查询返回

  Select * from 
  status LEFT JOIN ON status.profile_id = profile.profile_id 

但是当我放置一个 where 条件时它什么都不显示

  Select * from 
  status LEFT JOIN ON status.profile_id = profile.profile_id
  where profile.active= 1 and status.age > 40

左连接是右类型的JOIN吗?

最佳答案

您错过了连接表名称,profile.enabled 应该是 profile.active 试试这个:

 Select * 
 from 
      status  
      LEFT JOIN profile ON status.profile_id = profile.profile_id
 where 
      profile.active = 1 and status.age > 40

 Select * 
 from 
      status  
      LEFT JOIN profile ON status.profile_id = profile.profile_id and status.age > 40
 where 
      profile.active = 1 

关于php - mysql 加入 where 条件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24326062/

相关文章:

php - 如何通过PHP创建多个mysql连接

php - Laravel 验证一个应该正好是 10 位数字的数字

php - 在 PHP 中使用 exec 和转换调整图像大小

mysql - 在 MySQL 中获取最新记录

php - 错误异常 : Array to string conversion in PHP

mysql - 我需要跨多个表继承外键吗?

php - 列出数据库中的所有表

php - 带条件的 LEFT JOIN 未返回所需的数据

mysql - 如何编写具有多个左连接的 MySQL 删除

mysql - SQL left outer join中,如何只连接第一次出现的?