SQL OR
AND
เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) การเชื่อมวลีสำหรับเงื่อนไขต่าง ๆ
Database : MySQL,Microsoft Access,SQL Server,Oracle
Syntax
เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) การเชื่อมวลีสำหรับเงื่อนไขต่าง ๆ
Database : MySQL,Microsoft Access,SQL Server,Oracle
Syntax
SELECT
Column1,Column2,Column3,... FROM [Table-Name] WHERE [Field] = 'Value' [AND/OR]
[Field] = '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 การเลือกข้อมูลที่ CountryCode = US และ Used = 100000
SELECT
* FROM customer WHERE CountryCode = 'US' AND Used = '100000'
หรือ
SELECT * FROM customer WHERE CountryCode = 'TH' OR CountryCode = 'EN'
หรือ
SELECT * FROM customer WHERE CountryCode = 'TH' OR CountryCode = 'EN'
Output
|
CustomerID
|
Name
|
Email
|
CountryCode
|
Budget
|
Used
|
|
C004
|
Chalee
Angel
|
chalee.angel@thaicreate.com
|
US
|
4000000
|
100000
|
|
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
|
ไม่มีความคิดเห็น:
แสดงความคิดเห็น