ใช้ LIKE CONCAT('%', column, '%') ตรวจสอบว่าคอลัมน์หนึ่งมีค่าของอีกคอลัมน์หนึ่งอยู่ในตัวหรือไม่
สร้างตารางและเพิ่มข้อมูล
mysql> create table DemoTable (
FirstName varchar(100),
FullName varchar(100) );
Query OK, 0 rows affected (0.53 sec)
mysql> insert into DemoTable values('John','John Smith'); Query OK, 1 row affected (0.08 sec)
mysql> insert into DemoTable values('David','John Miller'); Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('Bob','Sam Miller'); Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('Chris','Chris Brown'); Query OK, 1 row affected (0.10 sec)
คิวรีหาแถวที่ FullName มี FirstName อยู่ในตัว
mysql> select FirstName,FullName from DemoTable
where FullName LIKE concat('%', FirstName, '%');
+-----------+-------------+ | FirstName | FullName | +-----------+-------------+ | John | John Smith | | Chris | Chris Brown | +-----------+-------------+ 2 rows in set (0.00 sec)
ผลลัพธ์: John อยู่ใน John Smith ✓, Chris อยู่ใน Chris Brown ✓ | David ไม่อยู่ใน John Miller, Bob ไม่อยู่ใน Sam Miller