将查询从Sqlite3转换为mysql

时间:2015-05-19 16:00:13

标签: mysql sql sqlite

我已将我的数据库从Sqlite3转换为mysql,但当我尝试执行此查询时:

SELECT * from main WHERE case_id IN
(
SELECT DISTINCT case_id FROM main WHERE subject LIKE '%word%' AND 
court = 'other'  ORDER BY RANDOM() LIMIT 100
)
ORDER BY case_id, date;

在sqlite3上工作,我在MySql上收到以下错误:

 #1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

任何人都可以帮我找出一个可以工作并产生相同结果的查询吗?感谢。

1 个答案:

答案 0 :(得分:2)

SELECT m1.*
from main m1
join 
(
   select case_id
   from main 
   where subject LIKE '%word%' 
   AND court = 'other'  
   ORDER BY RANDOM() 
   LIMIT 100
) m2 on m1.case_id = m2.case_id
ORDER BY m1.case_id, m1.date;