Skip to main content
Practice

Introduction to SELECT

The SELECT statement is the most commonly used SQL command. It allows you to retrieve specific data from one or more tables.

If you want to look at the data you've stored in a table, like student scores or exam results, you'll use SELECT. Whether it's a student's name, a list of passed students, or just the top scores, SELECT helps you fetch exactly what you need.


Basic SELECT Syntax

The example below shows how to retrieve data from a table using the SELECT statement:

Basic SELECT Syntax
SELECT column1, column2
FROM table_name;
  • SELECT specifies which columns to retrieve.
  • FROM specifies which table to retrieve the data from.

Select All Columns

The * is a wildcard that means "all columns".

Select all columns
SELECT * FROM mid_exam;

This query retrieves every column from the mid_exam table.


Example: View Names and Exam Scores

Let's say you have a table called mid_exam:

idnameexam_scorepassed
1John Miller78Yes
2Emily Davis91Yes
3Michael Johnson84Yes
4Sophia Wilson65No
5Ethan Brown88Yes

You can retrieve the names and exam scores using:

Select name and exam score
SELECT name, exam_score
FROM mid_exam;

This returns:

nameexam_score
John Miller78
Emily Davis91
Michael Johnson84
Sophia Wilson65
Ethan Brown88

Bonus: View Name and Passed Status

If you want to check who passed:

Select name and passed status
SELECT name, passed
FROM mid_exam;

This query shows whether each student passed the midterm.


Why select matters

The SELECT command is the starting point for exploring and analyzing data. Once you've mastered it, you'll move on to:

  • Filtering rows using WHERE
  • Sorting using ORDER BY
  • Combining multiple tables with JOIN

All these skills begin with understanding how SELECT works.