我想从mysql查询
中找到用户id
和Email
我在mysql数据库中有三个表
1.users
这是我的查询
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_date
和job_time
我的sql查询返回空白但o / p应该至少在行
提前致谢
答案 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
);