Course Resources

Search

Search IconIcon to open search

Last updated Nov 17, 2024

# Select and Filter Data - SELECT Statement

# Database Basics Refresher

Databases exist to help us store and manage large amounts of information in an organized way. In SQL this data is organized into tables consisting of rows and columns. Each table in a database represents a different entity, such as customers, products, or orders. The rows in the table represent individual records, and the columns represent the attributes of these entities.

# Example Table: Customers
CustomerIDFirstNameLastNameEmail
1JohnDoejohndoe@email.com
2JaneSmithjanesmith@email.com
3AlexJohnsonalexj@email.com

# SELECT Statements

The SELECT statement is used to retrieve data from a database. It allows you to specify exactly which data you want to fetch from a table.

# Basic SELECT Syntax
1
2
SELECT column1, column2, ...
FROM table_name;
# Selecting Specific Columns

To retrieve specific columns from a table, list the column names separated by commas. For example the query:

1
2
SELECT FirstName, LastName
FROM Customers;
# Expected Output:
FirstNameLastName
JohnDoe
JaneSmith
AlexJohnson
# Selecting All Columns

To select all columns from a table, use the asterisk * symbol:

1
2
SELECT *
FROM Customers;

This query will result in the entire Customers table being displayed.

# Practice Questions

  1. Select only the contact’s name and age columns from the Customer table.

# Lessons