MySQL还没有支持LIMIT& IN / ALL / ANY / SOME

时间:2017-09-01 01:54:33

标签: mysql subquery limit

SELECT *, 
IF(users_posts.uid IN (SELECT puid FROM post_ups WHERE  post_ups.uid = UID LIMIT 400 ) AND users_posts.uid  <> UID ,10,0)
    FROM users_posts

我收到此错误

  

这个版本的MySQL还没有支持&#39; LIMIT&amp; IN / ALL / ANY / SOME   子查询&#39;

我如何在子查询上使用限制,并且我可以将其转换为连接语句,并且这个查询对性能有利吗?理论上这可以运行+百万重新编码?

更新 这个代码会产生与上面相同的结果吗?

SELECT *,IF(ups.puid = t1.uid,10,0)
    FROM users_posts t1
    LEFT JOIN (SELECT puid FROM post_ups WHERE  post_ups.uid = 135 ORDER BY `created_date` DESC LIMIT 400 ) AS ups ON ups.puid = t1.uid  AND t1.uid  <> 135

1 个答案:

答案 0 :(得分:1)

您可以通过

执行此操作
`SELECT *, 
IF(users_posts.uid IN (select * from (SELECT puid FROM post_ups WHERE  post_ups.uid = UID LIMIT 400) tmp_tbl ) AND users_posts.uid  <> UID ,10,0)
    FROM users_posts`

或代替LEFT JOIN使用INNER JOIN。

SELECT *,IF(ups.puid = t1.uid,10,0)
FROM users_posts t1 INNER JOIN (SELECT puid FROM post_ups WHERE  post_ups.uid = 135 ORDER BY `created_date` DESC LIMIT 400 ) AS ups ON ups.puid = t1.uid  AND t1.uid  <> 135