Back to Course

SQL for Beginners with Hands-On Labs

0% Complete
0/0 Steps
Lesson 6 of 29
In Progress

SQL SELECT

The SELECT statement is used to fetch data from one or more tables in a database.

SQL SELECT Syntax

SQL Syntax Example
SQL
SELECT column1, column2, ...
FROM table_name;
  • column1, column2, ... are the columns you want to retrieve.
  • table_name is the name of the table from which to retrieve the data.

To select all columns from a table, you can use the asterisk (*) wildcard:

SQL Syntax Example
SQL
SELECT * FROM table_name;

SQL SELECT Examples

We’ll use the Patients table to demonstrate the functionality of the SELECT function.

SQL SELECT All Columns Example

To retrieve all information about patients, apply the SELECT * function directly to the table.

SQL Syntax Example
SQL
SELECT * FROM Patients;

SQL SELECT Specific Columns Example

To retrieve only the first and last names of all patients, apply the SELECT function to the first_name and last_name columns

SQL Syntax Example
SQL
SELECT first_name, last_name FROM Patients;

SQL SELECT Using WHERE Clause Example

To retrieve information about female patients, apply the SELECT * function directly to the table followed by the WHERE subquery to filter out the value 'F' from the gender column.

SQL Syntax Example
SQL
SELECT * FROM Patients
WHERE gender = 'F';

SQL SELECT From Specific Column Using WHERE Clause Example

To retrieve the contact numbers of male patients, apply the SELECT function to the contact_number column followed by the WHERE subquery to filter out the value 'M' from the gender column.

SQL Syntax Example
SQL
SELECT contact_number FROM Patients
WHERE gender = 'M';

SQL SELECT Labs

SQL Playground

Skip to content