我注意到了
(SELECT title, relavency, 'search1' as source FROM search1 ORDER BY relavency DESC LIMIT 10) UNION (SELECT title, relavency, 'search2' as source FROM search2 ORDER BY relavency DESC LIMIT 10) ORDER BY relavency DESC LIMIT 10
最后一个LIMIT 10不起作用。为什么?
错误是
“错误代码1064:...在'LIMIT 1000'附近使用”
为什么mysql workbench会将LIMIT 10检测为LIMIT 1000,但如果它的1000仍然可以工作?
答案 0 :(得分: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
仅供参考:您拼错了“相关性”,但我保留了拼写错误,因此查询可以正常工作。