sql-order-by

SQLite Order By places umlauts & speical chars at end

时光怂恿深爱的人放手 提交于 2019-12-19 09:46:59
问题 I'm using Phonegap to do a dictionary app for iOS. When querying the database for an alphabetical list I use COLLATE NOCASE : ORDER BY term COLLATE NOCASE ASC This solved the problem that terms starting with a lower case letter where appended to the end (Picked it up from that question). However non-standard characters as öäüéêè still get sorted in the end ~ here 2 examples: Expected: Öffnungszeiten Oberved: Zuzahlung Zuzahlung Öffnungszeiten (or) clé cliquer sur cliquer sur clé I looked

MySQL: ORDER BY with empty date '0000-00-00' as last but the rest ASC

╄→гoц情女王★ 提交于 2019-12-19 09:29:38
问题 In our database, instead of making empty dates NULL , they are '0000-00-00' (I know, it sucks). How can I order these so that dates that are not '0000-00-00' are first and ordered ASC , and then the empty dates of '0000-00-00' come after? Thanks! 回答1: ... ORDER BY CASE WHEN YourDateColumn = '0000-00-00' THEN 2 ELSE 1 END, YourDateColumn 回答2: Try Below : SELECT * FROM your_table ORDER BY (date_column='0000-00-00'), date_column ASC OR select * from your_table order by if(date_column='0000-00-00

MySQL: ORDER BY with empty date '0000-00-00' as last but the rest ASC

瘦欲@ 提交于 2019-12-19 09:29:37
问题 In our database, instead of making empty dates NULL , they are '0000-00-00' (I know, it sucks). How can I order these so that dates that are not '0000-00-00' are first and ordered ASC , and then the empty dates of '0000-00-00' come after? Thanks! 回答1: ... ORDER BY CASE WHEN YourDateColumn = '0000-00-00' THEN 2 ELSE 1 END, YourDateColumn 回答2: Try Below : SELECT * FROM your_table ORDER BY (date_column='0000-00-00'), date_column ASC OR select * from your_table order by if(date_column='0000-00-00

Syntax error near “ORDER BY order DESC” in MySQL?

懵懂的女人 提交于 2019-12-19 09:21:33
问题 Why I try to do an order by query, I always get an error telling me to check the syntax by the ORDER BY 'order' DESC.... Here's my query: SELECT * FROM posts ORDER BY order DESC; What am I doing wrong?? 回答1: order is a reserved word in SQL; case does not matter. It must be quoted when used as an identifier. From the MySQL Reserved Words documentation: Certain words such as SELECT, DELETE, or BIGINT [or ORDER] are reserved and require special treatment for use as identifiers such as table and

Is there a [straightforward] way to order results *first*, *then* group by another column, with SQL?

北城以北 提交于 2019-12-19 07:46:09
问题 I see that in SQL, the GROUP BY has to precede ORDER BY expression. Does this imply that ordering is done after grouping discards identical rows/columns? Because I seem to need to order rows by a timestamp column A first, THEN discarding rows with identical value in column A. Not sure how to accomplish this... I am using MySQL 5.1.41 create table ( A int, B timestamp ) The data could be: +-----+-----------------------+ | A | B | +-----+-----------------------+ | 1 | today | | 1 | yesterday |

How to Order MySQL VARCHAR Results

帅比萌擦擦* 提交于 2019-12-19 07:22:33
问题 In a SELECT statement, I have a varchar column with ORDER BY DESC on it. Examples of data in this column: 1234 987 12-a 13-bh MySQL would return the select something like the following: 987 12-a 1234 13-bh It puts three character long results before four character long results and so on. I would like it to ignore length and just sort the numbers that come before the '-' char. Is there something that I can ORDER on like SUBSTRING in an IF() which would remove all data in a row starting with

How does order by clause works if two values are equal?

孤者浪人 提交于 2019-12-19 05:48:11
问题 This is my NEWSPAPER table. National News A 1 Sports D 1 Editorials A 12 Business E 1 Weather C 2 Television B 7 Births F 7 Classified F 8 Modern Life B 1 Comics C 4 Movies B 4 Bridge B 2 Obituaries F 6 Doctor Is In F 6 When i run this query select feature,section,page from NEWSPAPER where section = 'F' order by page; It gives this output Doctor Is In F 6 Obituaries F 6 Births F 7 Classified F 8 But in Kevin Loney's Oracle 10g Complete Reference the output is like this Obituaries F 6 Doctor

How does order by clause works if two values are equal?

心已入冬 提交于 2019-12-19 05:48:04
问题 This is my NEWSPAPER table. National News A 1 Sports D 1 Editorials A 12 Business E 1 Weather C 2 Television B 7 Births F 7 Classified F 8 Modern Life B 1 Comics C 4 Movies B 4 Bridge B 2 Obituaries F 6 Doctor Is In F 6 When i run this query select feature,section,page from NEWSPAPER where section = 'F' order by page; It gives this output Doctor Is In F 6 Obituaries F 6 Births F 7 Classified F 8 But in Kevin Loney's Oracle 10g Complete Reference the output is like this Obituaries F 6 Doctor

Controlling the sibling order under recursive CTE?

…衆ロ難τιáo~ 提交于 2019-12-19 04:00:27
问题 I have a CTE query which looks for main leafs and sub leafs. but I'm having trouble controling the leaf selection order between 2 siblings : Each row in the table is declared as : (childID INT ,parentID INT ,NAME NVARCHAR(30),location int) Where location is a priority to sort IFF they are siblings. And so I have this tree structure : those pairs has a location priority : For example : `a` ( location=1) should be before `f` (location=2) `b` ( location=1) should be before `e` (location=2) `d` (

SQL Query, Selecting 5 most recent in each group

若如初见. 提交于 2019-12-19 02:32:32
问题 I have this table CREATE TABLE `codes` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `language_id` int(11) unsigned NOT NULL, `title` varchar(60) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `time_posted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 language_id refers to what language the record is in. What I would like to do is retrieve a list of the five most recent (ORDER BY time_posted DESC LIMIT 5) records in