TIP : การใช้ function like เพื่อค้นหาข้อมูล

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: TIP : การใช้ function like เพื่อค้นหาข้อมูล

Re: การใช้ function like เพื่อค้นหาข้อมูล

โดย M031 » 23/11/2015 10:04 pm

55555555555555555555555555555555555555+

Re: การใช้ function like เพื่อค้นหาข้อมูล

โดย konseo » 23/11/2015 9:59 pm

มีฟังชั่น love ไหมครับ อิอิ

TIP : การใช้ function like เพื่อค้นหาข้อมูล

โดย M031 » 21/11/2015 1:49 pm

โค้ด: เลือกทั้งหมด

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

ข้อมูลตัวอย่าง
test.PNG
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
test.PNG (16.37 KiB) Viewed 2949 times
2. จะ like ตัวที่มี S นำหน้าเท่านั้น จะได้ผลลัพธ์

โค้ด: เลือกทั้งหมด

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

โค้ด: เลือกทั้งหมด

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

โค้ด: เลือกทั้งหมด

select * from member where`mem_name` like '__S%';
test.PNG
test.PNG (7.03 KiB) Viewed 2949 times
สามารถศึกษาเพิ่มเติ่มได้ที่
http://www.techonthenet.com/sql/like.php

ลิ้งที่เกี่ยวข้อง
https://www.mindphp.com/developer/21-sql-mysql.html

ข้างบน