สร้างตารางตัวอย่าง
mysql> create table DemoTable (
-> FirstName varchar(20),
-> LastName varchar(20)
-> );
Query OK, 0 rows affected (1.44 sec)
เพิ่มข้อมูลตัวอย่าง
mysql> insert into DemoTable values('John', 'Smith');
Query OK, 1 row affected (0.35 sec)
mysql> insert into DemoTable values('Chris', 'Brown');
Query OK, 1 row affected (0.37 sec)
mysql> insert into DemoTable values('Carol', 'Taylor');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable values('David', 'Miller');
Query OK, 1 row affected (0.24 sec)
แสดงข้อมูลทั้งหมด
mysql> select * from DemoTable;
ผลลัพธ์
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | John | Smith | | Chris | Brown | | Carol | Taylor | | David | Miller | +-----------+----------+ 4 rows in set (0.00 sec)
คำสั่งเรียงลำดับด้วยหลายคอลัมน์
mysql> select * from DemoTable order by FirstName, LastName;
ผลลัพธ์
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Carol | Taylor | | Chris | Brown | | David | Miller | | John | Smith | +-----------+----------+ 4 rows in set (0.24 sec)
คำอธิบาย: เรียงตาม FirstName ก่อน (A-Z) ถ้า FirstName เหมือนกันค่อยเรียงตาม LastName ใช้คอมม่าคั่นระหว่างคอลัมน์