โค้ด: เลือกทั้งหมด
select * from table where columns like '%%';
การใช้ function like เพื่อหาข้อมูลใน database
จะยกตัวอย่างจากตารางฐานข้อมูลที่สร้างขึ้นมา ดังภาพ
ข้อมูลตัวอย่าง

- test.PNG (23.08 KiB) Viewed 2949 times
1. คำสั่งนี้จะเข้าไปหาข้อมูลใน table ที่ชื่อ member โดย ระบุ columns ที่ชื่อ mem_name โดย like ตัวที่มี S จะได้ผลลัพธ์
โค้ด: เลือกทั้งหมด
select * from member where`mem_name` like '%S%';

- test.PNG (16.37 KiB) Viewed 2949 times
2. จะ like ตัวที่มี S นำหน้าเท่านั้น จะได้ผลลัพธ์
โค้ด: เลือกทั้งหมด
select * from member where`mem_name` like 'S%';

- test.PNG (4.51 KiB) Viewed 2949 times
3. จะ like ตัวที่มี S อยู่ด้านหลังเท่านั้น จะได้ผลลัพธ์
โค้ด: เลือกทั้งหมด
select * from member where`mem_name` like '%S';

- test.PNG (4.45 KiB) Viewed 2949 times
4. จะ like ตัวที่ตำแหน่งที่ 3 เป็นตัว __S จะได้ผลลัพธ์
_ หนึ่งขีด แทน 1 ตำแหน่ง
โค้ด: เลือกทั้งหมด
select * from member where`mem_name` like '__S%';

- test.PNG (7.03 KiB) Viewed 2949 times
สามารถศึกษาเพิ่มเติ่มได้ที่
http://www.techonthenet.com/sql/like.php
ลิ้งที่เกี่ยวข้อง
https://www.mindphp.com/developer/21-sql-mysql.html