如何使用mysql查询查找用户信息

时间:2016-03-22 05:50:01

标签: php mysql json database

我想从mysql查询

中找到用户idEmail

我在mysql数据库中有三个表

  1. 用户2. photographer_timetables 3.jobs
  2. 1.users

    user table

    2.photographer_timetables photographer timetable

    3个工作 enter image description here

    这是我的查询

       SELECT Users.id AS `Users__id`
          , Users.email AS `Users__email` 
       FROM users          Users 
       LEFT 
       JOIN photographer_timetables pt    
         ON (pt.user_id = users.id AND role =3) 
      RIGHT JOIN jobs jb 
         ON (jb.photographer_id = pt.user_id 
         AND HOUR(jb.job_time) !='12:00:00'  
         AND jb.job_date !='2016-03-21')    
     WHERE (HOUR(start_time) <= '08:00:00'  
        AND weekday = 1)
    

    我想找到job_datejob_time

    中不可用的用户信息

    我的sql查询返回空白但o / p应该至少在行

    提前致谢

1 个答案:

答案 0 :(得分:2)

您可以使用NOT EXISTS

<强>查询

select * from users
where not exists (
  select 1 from jobs
  where jobs.user_id = users.id
);

希望一旦结束,您将从jobs表中删除该行。

如果您想查看特定日期的所有人。然后

<强>查询

select * from users
where not exists (
  select 1 from jobs
  where jobs.user_id = users.id
  and jobs.job_date = '2016-03-23' -- change the date accordingly
);