mysql Chinese sort effective method sql statement

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags create example mysql mysql tutorial network network programming programming question

In the mysql tutorial on Chinese sort is a more interesting question, especially for the field is uft-8 or not gbk, gb2312 field type is Chinese sort out there is a problem, let's look at an example.

create table `test111cnnet` (
`bid` int (4) unsigned not null auto_increment,
`namerean` varchar (20) character set gbk default null,
primary key (`id`)
); Save some data

insert into `test1` (` id`, `namerean`) values ​​('Li');
insert into `test1` (` id`, `namerean`) values ​​('Deng');
insert into `test1` (` id`, `namerean`) values ​​('station');

mysql tutorial> select namerean fromtest111cnnetorder by namerean;

Deng (d)
Lee (l)
Station (z)
This looks mysql Chinese sort is no problem, because our namerean is gbk encoding, so the result is satisfactory, then if uft-8 is not alright, so we constructed a,

select namerean from test111cnnet order by convert (namerean using gb2312) asc; In this way, no matter what the current field encoding, he can sort well according to the Chinese pinyin.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.