Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

วิธีรวมการเลือกแถว (Row Selection) และเลือกคอลัมน์ (Column Selection) ใน MySQL


ใช้ WHERE Clause รวมการเลือกแถวและคอลัมน์ ตัวอย่างตาราง Student:

mysql> Select * from Student;
+--------+--------+--------+
| Name   | RollNo | Grade  |
+--------+--------+--------+
| Gaurav |    100 | B.tech |
| Aarav  |    150 | M.SC   |
| Aryan  |    165 | M.tech |
+--------+--------+--------+
3 rows in set (0.00 sec)

รวม Row และ Column Selection:

mysql> Select Name, RollNo, Grade from Student where Grade='M.Sc' or Grade='B.Tech';
+--------+--------+--------+
| Name   | RollNo | Grade  |
+--------+--------+--------+
| Gaurav |    100 | B.tech |
| Aarav  |    150 | M.SC   |
+--------+--------+--------+
2 rows in set (0.00 sec)

คำอธิบาย: SELECT ระบุคอลัมน์ (Column Selection) WHERE กรองแถว (Row Selection)