Tạo bảng:
mysql> create table DemoTable2009 ( Name varchar(20) ); Query OK, 0 rows affected (0.51 sec)
Thêm dữ liệu:
mysql> insert into DemoTable2009 values('John Doe'); Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable2009 values('Adam Smith'); Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable2009 values('John Smith'); Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable2009 values('David Miller'); Query OK, 1 row affected (0.18 sec)
Hiển thị dữ liệu:
mysql> select * from DemoTable2009;
+--------------+ | Name | +--------------+ | John Doe | | Adam Smith | | John Smith | | David Miller | +--------------+ 4 rows in set (0.00 sec)
Truy vấn dùng LIKE hai lần với OR:
mysql> select * from DemoTable2009 where Name like '%Smith%' or Name like '%David%';
Kết quả:
+--------------+ | Name | +--------------+ | Adam Smith | | John Smith | | David Miller | +--------------+ 3 rows in set (0.00 sec)