Write a query to get data of selected columns from a table
Description: Show only the name and the city of every student.
Tables: the exercises use the students (id, name, city, marks, course_id) and courses (id, course_name) tables, with the data from our MySQL INSERT chapter. The students are: Robin (Delhi, 85), Maria (Mumbai, 92), John (Pune, 78), Asha (Jaipur, 88), Vikram (Delhi, 65), Neha (Mumbai, 45).
Hint:
- Write the column names after
SELECT, separated by commas.
MySQL query for selected columns
SELECT name, city
FROM students;
Output:
Tutorials Class - Output Window
| name | city |
|---|---|
| Robin | Delhi |
| Maria | Mumbai |
| John | Pune |
| Asha | Jaipur |
| Vikram | Delhi |
| Neha | Mumbai |
How it works
- Only the listed columns are returned.
SELECT *returns all the columns.
Read MySQL SELECT.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |