วันอังคารที่ 9 ธันวาคม พ.ศ. 2557

คำสั่ง SQL LIKE

SQL LIKE 

เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) โดยทำการค้นหาข้อความที่ระบุภายในฟิวด์ที่กำหนด

Database : MySQL,Microsoft Access,SQL Server,Oracle

Syntax

SELECT Column1,Column2,Column3,... FROM [Table-Name] WHERE [Filed] LIKE '%Value%'


Table : customer
CustomerID
Name
Email
CountryCode
Budget
Used
C001
Win Weerachai
win.weerachai@thaicreate.com
TH
1000000
600000
C002
John Smith
john.smith@thaicreate.com
EN
2000000
800000
C003
Jame Born
jame.born@thaicreate.com
US
3000000
600000
C004
Chalee Angel
chalee.angel@thaicreate.com
US
4000000
100000


Sample1 การเลือกข้อมูลตารางที่ฟิวด์ Name มีคำว่า ee อยู่

SELECT * FROM customer WHERE Name LIKE '%ee%'

Output

CustomerID
Name
Email
CountryCode
Budget
Used
C001
Win Weerachai
win.weerachai@thaicreate.com
TH
1000000
600000
C004
Chalee Angel
chalee.angel@thaicreate.com
US
4000000
100000


Sample2 การเลือกข้อมูลตารางที่ฟิวด์ Email มีคำว่า j นำหน้า

SELECT * FROM customer WHERE Name LIKE 'j%'

Output

CustomerID
Name
Email
CountryCode
Budget
Used
C002
John Smith
john.smith@thaicreate.com
EN
2000000
800000
C003
Jame Born
jame.smith@thaicreate.com
US
3000000
600000


Sample3 การเลือกข้อมูลตารางที่ฟิวด์ Name มีคำว่า i ลงท้าย

SELECT * FROM customer WHERE Name LIKE '%i'

Output


CustomerID
Name
Email
CountryCode
Budget
Used
C001
Win Weerachai
win.weerachai@thaicreate.com
TH
1000000
600000

ไม่มีความคิดเห็น:

แสดงความคิดเห็น