SELECT u.id, u.level, u.first_name, u.last_name, u.email
FROM users u
INNER JOIN user_companies uc ON u.id = uc.user_id
LEFT JOIN ( SELECT s.user_id, s.start, s.stop, s.break, s.task
FROM schedule s
WHERE s.start>? AND s.stop<? AND s.multi_id=?)
as s ON (u.id = s.user_id)
WHERE uc.comp_id=? AND uc.status=1 AND
NOT EXISTS (SELECT 1 FROM schedule_remove sc
WHERE sc.user_id=u.id AND sc.sched_id=?)
疯狂的查询,简单的问题。如何将s.start, s.stop, s...
纳入我的结果查询?现在我可以拉的是u.level,u.first_name等等。
谢谢!
更新
我是个白痴。感谢websch01lar推动实现这一点。将s.stop等添加到主列表就像它应该的那样。在尝试显示结果之前,我只是没有检查$ r ['stop']是否为空。答案 0 :(得分:0)
只需在主/外部查询中包含这些s.*
列,并对该表进行内部联接,如下所示
SELECT u.id, u.level, u.first_name, u.last_name, u.email,
s.user_id, s.start, s.stop, s.break, s.task <-- Here
FROM users u
INNER JOIN user_companies uc ON u.id = uc.user_id
INNER JOIN schedule s ON u.id = s.user_id
AND (s.start>? AND s.stop<? AND s.multi_id=?)
WHERE
uc.comp_id=? AND uc.status=1 AND
NOT EXISTS (SELECT 1 FROM schedule_remove sc
WHERE sc.user_id=u.id AND sc.sched_id=?)