MySQL中的UNION和ORDER BY问题 [英] UNION and ORDER BY issue in MySQL

查看:131
本文介绍了MySQL中的UNION和ORDER BY问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您应该在这里看到我正在尝试执行的操作,但是它不起作用

You should see what I'm trying to do here but it's not working

$getquery = "SELECT * 
FROM highscore 
WHERE score >= '$score'
ORDER BY score ASC
LIMIT 6

UNION

SELECT * 
FROM highscore 
WHERE score < '$score'
ORDER BY score DESC
LIMIT 5";

mysql_error()返回:不正确使用ORDER BY和UNION".

mysql_error() returns: "improper usage of ORDER BY and UNION".

推荐答案

尝试:

$getquery = "(SELECT * 
FROM highscore 
WHERE score >= '$score'
ORDER BY score ASC
LIMIT 6)

UNION ALL -- guaranteed to be beneficial in this case as Johan commented

(SELECT * 
FROM highscore 
WHERE score < '$score'
ORDER BY score DESC
LIMIT 5)";

请参阅对我的评论回答相关问题.
咨询详细手册.

See the comments to my answer on the related question.
Or consult the fine manual.

这篇关于MySQL中的UNION和ORDER BY问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆