MySQL还没有支持' LIMIT& IN / ALL / ANY / SOME子查询'

时间:2017-06-13 09:26:37

标签: mysql

我正在运行此查询

SELECT * FROM 
tb_emp_daily_status d 
where 
d.shiftdate>='2017-06-07' and 
shiftdate<='2017-06-13' and 
emp_id in (SELECT id FROM tb_employee e WHERE e.user_id = '18145' LIMIT 20) 
order by d.id asc

如何在mysql中编写此查询

3 个答案:

答案 0 :(得分:2)

试试这个:

  SELECT * FROM 
    tb_emp_daily_status d 
    where 
    d.shiftdate>='2017-06-07' and 
    shiftdate<='2017-06-13' and 
    emp_id in (SELECT * FROM (SELECT id FROM tb_employee e WHERE e.user_id = '18145' LIMIT 20)   
          as t)
    order by d.id asc

答案 1 :(得分:0)

而不是IN子选择,您可以使用与子选择结果的连接

  SELECT * FROM 
  tb_emp_daily_status d 
  INNER JOIN ( 
    SELECT id FROM tb_employee e WHERE e.user_id = '18145' LIMIT 20
  ) t on d.emp_id = t.id
  where d.shiftdate>='2017-06-07' and 
  shiftdate<='2017-06-13' and 
  order by d.id asc

答案 2 :(得分:0)

使用INNER JOIN而不是IN子句