Choosing columns
Picking columns
SELECT * returns every column. Usually you want only a few. Instead of *, list the columns you want, separated by commas:
The result has just those columns, in the order you wrote them.
การเลือกคอลัมน์
SELECT * ส่งคืน ทุก คอลัมน์ โดยปกติคุณต้องการเพียงไม่กี่ Instead of *,列出你想要的列用逗号隔开:
SELECT name, score FROM student;
ผลลัพธ์จะมีแค่คอลัมน์เหล่านั้น ตามลำดับที่คุณเขียน
Renaming a column with AS
You can rename a column in the result with AS. This does not change the table — only the heading shown:
The headings become pupil and mark. This is handy for clear reports.
เปลี่ยนชื่อคอลัมน์ด้วย AS
คุณสามารถเปลี่ยนชื่อคอลัมน์ ในผลลัพธ์ ด้วย AS สิ่งนี้ไม่เปลี่ยนแปลงตาราง — เพียงแต่เปลี่ยนหัวเรื่องที่แสดง:
SELECT name AS pupil, score AS mark FROM student;
หัวเรื่องจะกลายเป็น pupil และ mark ซึ่งมีประโยชน์สำหรับรายงานที่ชัดเจน
Common mistakes
- List the columns you want, separated by commas.
ASrenames a column in the result.
ข้อผิดพลาดทั่วไป
- List the columns you want, separated by commas.
ASrenames a column in the result.
SELECT picks columns
Choosing columns keeps only the fields you name.
Select only the name and score columns from student, in that order. · เลือกเฉพาะคอลัมน์ name และ score จาก student โดยเรียงตามลำดับนั้น
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่
Select name and score, but rename the headings to pupil and mark using AS. · เลือก name และ score แต่เปลี่ยนชื่อหัวคอลัมน์เป็น pupil และ mark โดยใช้ AS
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่