สร้างตารางตัวอย่าง
mysql> create table DemoTable (
-> Name text
-> );
Query OK, 0 rows affected (1.31 sec)
เพิ่มข้อมูลตัวอย่าง (มีคำว่า "name" ที่ต้องการข้าม)
mysql> insert into DemoTable values('John 7');
Query OK, 1 row affected (0.65 sec)
mysql> insert into DemoTable values('John 6');
Query OK, 1 row affected (0.42 sec)
mysql> insert into DemoTable values('John 9');
Query OK, 1 row affected (0.33 sec)
mysql> insert into DemoTable values('name John 3');
Query OK, 1 row affected (0.24 sec)
แสดงข้อมูลทั้งหมด
mysql> select * from DemoTable;
ผลลัพธ์
+-------------+ | Name | +-------------+ | John 7 | | John 6 | | John 9 | | name John 3 | +-------------+ 4 rows in set (0.00 sec)
คำสั่งเรียงลำดับข้ามคำเฉพาะ
mysql> select * from DemoTable ORDER BY TRIM(REPLACE(LOWER(Name), 'name ', ''));
ผลลัพธ์
+-------------+ | Name | +-------------+ | name John 3 | | John 6 | | John 7 | | John 9 | +-------------+ 4 rows in set (0.00 sec)
คำอธิบาย: LOWER() ทำให้เป็นตัวพิมพ์เล็ก REPLACE() ลบคำ 'name ' ออก TRIM() ตัดช่องว่างนำหน้าท้าย แล้วค่อย ORDER BY