【问题标题】:mysqli inner join: data not exist in other tablemysqli内部连接:其他表中不存在数据
【发布时间】:2017-11-11 00:28:47
【问题描述】:

我有 3 个表,我正在使用内部联接从表中获取数据。

 select b.pic,b.fname,b.lname, a.job_id, a.uid, a.job_title, a.description, a.city, a.position, 
        a.salary, a.looking_for,a.website,a.date
   from job_posting a 
  inner join users b
  inner join job_applied c on a.uid = b.uid and b.uid = c.uid
  where c.job_id IS NULL and c.uid IS NULL and a.looking_for = 'student'

以上查询未返回任何数据。是空的。

让我解释一下表格。

job_posting - 包含工作信息。
用户 - 包含发布工作的用户信息。
job_applied - 包含用户已申请的职位。

所以,我想得到那些没有申请的工作。在 Job_paplied 表中,我有 job_id 和 uid。

【问题讨论】:

标签: mysql


【解决方案1】:

而不是inner join 尝试LEFT JOIN 喜欢:

select b.pic,b.fname,b.lname, a.job_id, a.uid, a.job_title,a.description,a.city, a.position, 
a.salary, a.looking_for,a.website,a.date from job_posting a  
LEFT JOIN users b  on a.uid = b.uid 
LEFT JOIN job_applied c  on b.uid = c.uid
where c.job_id IS NULL  and a.looking_for = 'student'

然后再试一次。

【讨论】:

  • 出现错误 - #1064 - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以了解在 'where c.job_id IS NULL and c.uid IS NULL and a.looking_for = 'student' 附近使用的正确语法
  • 检查这些列是否存在于关联表中?
  • @calculatingmachine 已修复。
  • 没有错误,但如果作业已应用并且存在于 job_applied 表中,则会显示数据。
  • 我申请了 3 份工作 1 但我仍然获得 3 条记录。
猜你喜欢
  • 2011-03-01
  • 2012-04-14
  • 2016-11-19
  • 1970-01-01
  • 2013-07-07
  • 2019-12-30
  • 1970-01-01
  • 2022-01-17
  • 2018-10-07
相关资源
最近更新 更多