2017-06-13 63 views
0

當我運行此查詢的MySQL還不支持 '限制和IN/ALL/ANY/SOME子查詢'

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的這個查詢

+1

你得到的錯誤是什麼? –

+1

不相關:如果沒有'ORDER BY',你的子查詢看起來很奇怪。 – zerkms

+0

[MySQL - 此版本的MySQL尚不支持'LIMIT&IN/ALL/ANY/SOME子查詢]的可能重複(https://stackoverflow.com/questions/17892762/mysql-this-version-of-mysql -doesnt至今沒有支持限制功能於所有任何-一些-subqu) – EstevaoLuis

回答

1

試試這個:

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 
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 
聯接
0

使用INNER JOIN而不是IN子句