1. <small id='Gecrz'></small><noframes id='Gecrz'>

      • <bdo id='Gecrz'></bdo><ul id='Gecrz'></ul>
      <tfoot id='Gecrz'></tfoot>
    2. <legend id='Gecrz'><style id='Gecrz'><dir id='Gecrz'><q id='Gecrz'></q></dir></style></legend>
      <i id='Gecrz'><tr id='Gecrz'><dt id='Gecrz'><q id='Gecrz'><span id='Gecrz'><b id='Gecrz'><form id='Gecrz'><ins id='Gecrz'></ins><ul id='Gecrz'></ul><sub id='Gecrz'></sub></form><legend id='Gecrz'></legend><bdo id='Gecrz'><pre id='Gecrz'><center id='Gecrz'></center></pre></bdo></b><th id='Gecrz'></th></span></q></dt></tr></i><div id='Gecrz'><tfoot id='Gecrz'></tfoot><dl id='Gecrz'><fieldset id='Gecrz'></fieldset></dl></div>
      1. mysql order by with union 似乎不起作用

        mysql order by with union doesn#39;t seem to work(mysql order by with union 似乎不起作用)
            <tbody id='qbrPA'></tbody>
            <tfoot id='qbrPA'></tfoot>
          1. <i id='qbrPA'><tr id='qbrPA'><dt id='qbrPA'><q id='qbrPA'><span id='qbrPA'><b id='qbrPA'><form id='qbrPA'><ins id='qbrPA'></ins><ul id='qbrPA'></ul><sub id='qbrPA'></sub></form><legend id='qbrPA'></legend><bdo id='qbrPA'><pre id='qbrPA'><center id='qbrPA'></center></pre></bdo></b><th id='qbrPA'></th></span></q></dt></tr></i><div id='qbrPA'><tfoot id='qbrPA'></tfoot><dl id='qbrPA'><fieldset id='qbrPA'></fieldset></dl></div>

            <small id='qbrPA'></small><noframes id='qbrPA'>

              <bdo id='qbrPA'></bdo><ul id='qbrPA'></ul>

                • <legend id='qbrPA'><style id='qbrPA'><dir id='qbrPA'><q id='qbrPA'></q></dir></style></legend>
                  本文介绍了mysql order by with union 似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这是我的查询

                  (SELECT * FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%only three doors%" OR `joke` LIKE "%only three doors%") ORDER BY `ups` DESC,`downs` ASC)
                  UNION
                  (SELECT * FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%only%" OR `joke` LIKE "%only%") ORDER BY `ups` DESC,`downs` ASC)
                  UNION
                  (SELECT * FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%three%" OR `joke` LIKE "%three%") ORDER BY `ups` DESC,`downs` ASC)
                  UNION
                  (SELECT * FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%doors%" OR `joke` LIKE "%doors%") ORDER BY `ups` DESC,`downs` ASC)
                   LIMIT 0, 30
                  

                  出于某种原因,它似乎没有按升序或降序排序……它只是按照它们在数据库中的自然顺序将结果扔回去.

                  For some reason it doesn't seem to order by ups or downs...it just tosses me back the results in the order they are naturally in the database.

                  当我将其缩减为一个查询时,它工作正常,但除此之外,它似乎忽略了它.

                  When I cut it down to only one query, it works fine, but other than that, it seems to ignore it.

                  我也不想按整个结果排序,否则我会把 LIMIT 0,30 Order By blah

                  I also don't want to order by the entire results, or I would have put LIMIT 0,30 Order By blah

                  推荐答案

                  来自 MySQL 文档:

                  ... 对单个 SELECT 语句使用 ORDER BY 意味着没有关于行在最终结果中出现的顺序因为 UNION 默认生成一组无序的行.

                  ... use of ORDER BY for individual SELECT statements implies nothing about the order in which the rows appear in the final result because UNION by default produces an unordered set of rows.

                  基本上,联合中的 ORDER 唯一有用的时候是如果您同时使用 LIMIT.

                  Basically the only time an ORDER in a union will be useful is if you are using LIMIT as well.

                  所以如果你查询是这样的:

                  So if you query was like this:

                  (SELECT * FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%only three doors%" OR `joke` LIKE "%only three doors%") ORDER BY `ups` DESC,`downs` ASC LIMIT 10)
                  UNION ...
                  

                  然后您会看到根据该顺序返回的前十条记录,但它们不一定按顺序显示.

                  Then you would see the first ten records that would be returned based on that order, but they wouldn't necessarily be displayed in order.

                  更新:

                  试试这个 -

                  (SELECT *, 1 as ob FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%only three doors%" OR `joke` LIKE "%only three doors%") )
                  UNION
                  (SELECT *, 2 as ob FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%only%" OR `joke` LIKE "%only%") )
                  UNION
                  (SELECT *, 3 as ob FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%three%" OR `joke` LIKE "%three%") )
                  UNION
                  (SELECT *, 4 as ob FROM `jokes` WHERE `flags` < 5 AND (`title` LIKE "%doors%" OR `joke` LIKE "%doors%"))
                   ORDER BY `ob`, `ups` DESC,`downs` ASC LIMIT 0, 30
                  

                  这篇关于mysql order by with union 似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)
                  Does MySQL have time-based triggers?(MySQL 有基于时间的触发器吗?)
                  is it possible to call a sql script from a stored procedure in another sql script?(是否可以从另一个 sql 脚本中的存储过程调用 sql 脚本?)
                  Procedure to loop through comma separated string is not working(遍历逗号分隔字符串的过程不起作用)
                • <tfoot id='eBxDC'></tfoot>
                    <tbody id='eBxDC'></tbody>

                  <small id='eBxDC'></small><noframes id='eBxDC'>

                    <bdo id='eBxDC'></bdo><ul id='eBxDC'></ul>
                    1. <i id='eBxDC'><tr id='eBxDC'><dt id='eBxDC'><q id='eBxDC'><span id='eBxDC'><b id='eBxDC'><form id='eBxDC'><ins id='eBxDC'></ins><ul id='eBxDC'></ul><sub id='eBxDC'></sub></form><legend id='eBxDC'></legend><bdo id='eBxDC'><pre id='eBxDC'><center id='eBxDC'></center></pre></bdo></b><th id='eBxDC'></th></span></q></dt></tr></i><div id='eBxDC'><tfoot id='eBxDC'></tfoot><dl id='eBxDC'><fieldset id='eBxDC'></fieldset></dl></div>
                        <legend id='eBxDC'><style id='eBxDC'><dir id='eBxDC'><q id='eBxDC'></q></dir></style></legend>