6

我注意到

(SELECT title, relavency, 'search1' as source FROM search1
ORDER BY relavency DESC
限制 10)
联盟
(SELECT title, relavency, 'search2' as source FROM search2
ORDER BY relavency DESC
限制 10)
ORDER BY relavency DESC
限制 10

最后的 LIMIT 10 不起作用。为什么?

错误是

“错误代码 1064:...在 'LIMIT 1000' 附近使用”

mysql 工作台如何将 LIMIT 10 检测为 LIMIT 1000,但如果它的 1000 它仍然可以工作?

4

1 回答 1

5

可以使用别名嵌套子查询重写您的查询。这应该适合你:

SELECT u.* FROM (
    (SELECT s1.title, s1.relavency, 'search1' as source FROM search1 AS s1
    ORDER BY s1.relavency DESC
    LIMIT 10)
        UNION 
    (SELECT s2.title, s2.relavency, 'search2' as source FROM search2 AS s2
    ORDER BY s2.relavency DESC
    LIMIT 10)
) AS u ORDER BY u.relavency DESC 
LIMIT 10

仅供参考:您拼错了“相关性”,但我保留了拼写错误,因此查询可以正常工作。

于 2009-09-27T02:25:44.240 回答