mysql排序错误_这是MySQL排序错误吗?

我面临奇怪的服务器行为MySQL 5.1.50 . 它错误地排序记录 .

例如,我创建了一个表 test :

CREATE TABLE IF NOT EXISTS `test` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`title` varchar(250) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `test` (`id`, `title`) VALUES

(1, 'record1'),

(2, 'record2'),

(3, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'),

(4, 'ABCDEFGHIJKLMNOPQRSTUVWXYY');

并进行查询:

mysql> set names utf8;查询正常,0行受影响(0.00秒)

mysql>按 Headers asc从测试顺序中选择*;

+----+----------------------------+

| id | title |

+----+----------------------------+

| 3 | ABCDEFGHIJKLMNOPQRSTUVWXYZ |

| 4 | ABCDEFGHIJKLMNOPQRSTUVWXYY |

| 1 | record1 |

| 2 | record2 |

+----+----------------------------+

4行(0.00秒)

mysql>按 Headers desc从测试顺序中选择*;

+----+----------------------------+

| id | title |

+----+----------------------------+

| 2 | record2 |

| 1 | record1 |

| 3 | ABCDEFGHIJKLMNOPQRSTUVWXYZ |

| 4 | ABCDEFGHIJKLMNOPQRSTUVWXYY |

+----+----------------------------+

4行(0.00秒)

如您所见,记录3和4不会改变位置

我做了这样的查询,有些字母不会改变订单,例如A和a .

mysql> SELECT * FROM test ORDER BY title COLLATE utf8_unicode_ci ASC;

+----+---------+

| id | title |

+----+---------+

| 1 | A |

| 27 | a |

| 28 | b |

| 2 | B |

| 29 | c |

| 3 | C |

| 4 | D |

| 30 | d |

| 31 | e |

| 5 | E |

| 6 | F |

| 32 | f |

| 33 | g |

| 7 | G |

| 34 | h |

| 8 | H |

| 35 | i |

| 9 | I |

| 36 | j |

| 10 | J |

| 11 | K |

| 37 | k |

| 12 | L |

| 38 | l |

| 39 | m |

| 13 | M |

| 40 | n |

| 14 | N |

| 41 | o |

| 15 | O |

| 42 | p |

| 16 | P |

| 17 | Q |

| 43 | q |

| 44 | r |

| 18 | R |

| 19 | S |

| 45 | s |

| 20 | T |

| 46 | t |

| 21 | U |

| 47 | u |

| 48 | v |

| 22 | V |

| 49 | w |

| 23 | W |

| 50 | x |

| 24 | X |

| 25 | Y |

| 51 | y |

| 26 | Z |

| 52 | z |

+----+---------+

mysql> SELECT * FROM test ORDER BY title COLLATE utf8_unicode_ci DESC;

+----+---------+

| id | title |

+----+---------+

| 52 | z |

| 26 | Z |

| 25 | Y |

| 51 | y |

| 50 | x |

| 24 | X |

| 49 | w |

| 23 | W |

| 48 | v |

| 22 | V |

| 47 | u |

| 21 | U |

| 20 | T |

| 46 | t |

| 45 | s |

| 19 | S |

| 18 | R |

| 44 | r |

| 17 | Q |

| 43 | q |

| 16 | P |

| 42 | p |

| 41 | o |

| 15 | O |

| 40 | n |

| 14 | N |

| 39 | m |

| 13 | M |

| 12 | L |

| 38 | l |

| 11 | K |

| 37 | k |

| 10 | J |

| 36 | j |

| 9 | I |

| 35 | i |

| 8 | H |

| 34 | h |

| 7 | G |

| 33 | g |

| 32 | f |

| 6 | F |

| 5 | E |

| 31 | e |

| 4 | D |

| 30 | d |

| 29 | c |

| 3 | C |

| 2 | B |

| 28 | b |

| 1 | A |

| 27 | a |

+----+---------+

我认为这是整理的错误 .

可能有人碰到这样的服务器行为?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值