Selecting Data
Selecting Data
Definition: The SELECT statement is used to retrieve data from a database. It allows you to "query" the table and pull out exactly the information you need to view.
Importance: In every beginner SQL curriculum, SELECT is treated as the most vital command. Since the primary purpose of a database is to provide information, mastering how to search and retrieve data is your first major step toward becoming a data professional.
Syntax
The basic query requires two parts: what you want to see (SELECT) and where it is located (FROM).
SELECT column_name FROM table_name;
Example: Specific Columns
If you only need a list of student names and their respective cities, you specify those column names separated by a comma:
SELECT name, city FROM students;
Selecting All Columns (The Wildcard)
If you want to see the entire table with all its columns and rows, you can use the asterisk (*) as a shorthand wildcard.
SELECT * FROM students;
Explanation
- Filtering by Column:
SELECT name, cityignores all other columns (like ID or Age), giving you a clean, focused result set. - The Asterisk (*): Using
SELECT *is convenient during testing, but in large professional databases, it is often better to name specific columns to improve speed and performance.
Key Notes
- Read-Only Action: Running a
SELECTstatement does not change, delete, or move your data. It simply creates a temporary view of the data for you to read. - Column Order: The order in which you list the columns in your
SELECTstatement is the order in which they will appear in your result grid. - Case Insensitivity: While
SELECTis usually written in uppercase for readability, the database will still understandselectorSelect.
🏋️ Test Yourself With Exercises
Take our quiz on Selecting Data to test your knowledge.
Browse Quizzes »