0% found this document useful (0 votes)
66 views14 pages

Querying Data With The SELECT Statement: Jon Flanders

The SELECT statement allows users to query data from database tables. It contains a SELECT list that specifies the columns to retrieve. A FROM clause defines the table being queried. The SELECT statement can use DISTINCT to return only unique values and constrain the number of results. It is a fundamental command for extracting data from databases.

Uploaded by

Enrik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views14 pages

Querying Data With The SELECT Statement: Jon Flanders

The SELECT statement allows users to query data from database tables. It contains a SELECT list that specifies the columns to retrieve. A FROM clause defines the table being queried. The SELECT statement can use DISTINCT to return only unique values and constrain the number of results. It is a fundamental command for extracting data from databases.

Uploaded by

Enrik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Querying Data with the SELECT

Statement

Jon Flanders

@jonflanders www.jonflanders.com
You can think of a SELECT
statement as a question you
are asking the database.
Example Questions

Who are all my


Who are all my How many
contacts with a
contacts? contacts do I have?
first name of Jon?
A Simple Query With SELECT
SELECT CLAUSE

{
SELECT ‘Hello’,‘World’;

{
SELECT LIST
Most of the time it contains a list of columns
from a table you want to query.
The SELECT 
 Then, a FROM clause is required.
List After every column comes a comma.
Except: no comma after the last column.
SELECT <COLUMN_NAME>, <COLUMN_NAME> FROM <TABLE_NAME> ;

SELECT first_name, last_name FROM person ;


* This wildcard "SELECT list" character
pulls all the columns from a table

BAD PRACTICE!
On my screen, these are both not
centered, but are about 2/3 down the
slide. Also, font sizes are different on
either side.

FROM Clause Defines the table you want to query

Multiple-Table FROM Clauses covered later in this course!


Qualifying Column Name with Table Name

SELECT first_name, last_name FROM person ;

SELECT person.first_name, person.last_name FROM person ;

Good Practice
Aliasing the Table Name

SELECT person.first_name, person.last_name FROM person ;

SELECT p.first_name, p.last_name FROM person p ;

Best Practice
Ways to Constrain the Number of Results

WHERE CLAUSE DISTINCT Qualifier

The WHERE clause is covered in the next module!


NOT DISTINCT
first_name

Jon

Jon

Fritz
What are the first names of all the
people I know? Shannon

Jason

Jason

Brian
SELECT p.first_name FROM person p ;
Brian
DISTINCT
first_name

Jon

Fritz

Shannon
What are all unique first names of
the people I know? Jason

Brian

SELECT DISTINCT p.first_name FROM person p ;


Query data with the SELECT command
Summary
The SELECT list defines the columns
The FROM clause defines the table
DISTINCT constrains results to unique
values

You might also like