Combining conditions
A WHERE clause can test more than one thing at once. Join conditions with:
AND— both must be trueOR— at least one must be trueNOT— flips a condition
This returns 11A students who also scored above 88.
การรวมเงื่อนไข
clause WHERE สามารถทดสอบหลายอย่างพร้อมกันได้ เชื่อมเงื่อนไขด้วย:
AND— ต้องเป็นจริง ทั้งคู่OR— ต้องเป็นจริง อย่างน้อยหนึ่งNOT— กลับด้านเงื่อนไข
SELECT name FROM student WHERE form = '11A' AND score > 88;
สิ่งนี้จะคืนมานักเรียนชั้น 11A ที่ได้คะแนน มากกว่า 88 ด้วย
Mixing AND and OR
When you mix AND and OR, use brackets to make the meaning clear, just like in maths:
AND is checked before OR, so brackets remove any doubt about what you mean.
การผสม AND และ OR
เมื่อคุณผสม AND และ OR ให้ใช้ วงเล็บ เพื่อให้ความหมายชัดเจน เหมือนกับคณิตศาสตร์:
SELECT name FROM student
WHERE form = '11B' OR score >= 95;
AND จะถูกตรวจสอบก่อน OR ดังนั้นวงเล็บจึงช่วยขจัดความสงสัยว่าคุณหมายถึงอะไร
Common mistakes
- Use brackets when you mix
ANDandORto make the order clear. NOTreverses a condition.
ข้อผิดพลาดทั่วไป
- ใช้วงเล็บเมื่อผสม
ANDและORเพื่อบอกลำดับให้ชัดเจน NOTกลับด้านเงื่อนไข
AND, OR, NOT
Combine conditions with AND/OR/NOT — see the truth table. · รวมเงื่อนไขด้วย AND/OR/NOT — ดู ตารางความจริง
Show the name of every student who is in form 11A and scored more than 88. · แสดง name ของนักเรียนทุกคนที่อยู่ในชั้น 11A และ มีคะแนนมากกว่า 88
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Show the name of every student who is in form 11B or scored 95 or more. · แสดง name ของนักเรียนทุกคนที่อยู่ในชั้น 11B หรือ มีคะแนน 95 ขึ้นไป
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่