Online College Courses for Credit

+
1 Tutorials that teach SQL Clauses
Take your pick:
SQL Clauses

SQL Clauses

Rating:
Rating
(0)
Author: Sophia Tutorial
Description:

Recall the three main SQL clauses and their functions.

(more)
See More
Fast, Free College Credit

Developing Effective Teams

Let's Ride
*No strings attached. This college course is 100% free and is worth 1 semester credit.

37 Sophia partners guarantee credit transfer.

299 Institutions have accepted or given pre-approval for credit transfer.

* The American Council on Education's College Credit Recommendation Service (ACE Credit®) has evaluated and recommended college credit for 32 of Sophia’s online courses. Many different colleges and universities consider ACE CREDIT recommendations in determining the applicability to their course and degree programs.

Tutorial

what's covered
At the conclusion of this tutorial, you will be able to recall the three main SQL clauses and their functions. This tutorial explores the three main SQL clauses of a SQL query in three parts:
  1. Getting Started
  2. Running A Query
  3. Adding WHERE

1. Getting Started

A database generally has one or more tables with each table identified by the table name. If you run the Postgres environment, you will see the list of tables under the schema browser with the columns of data and their data types listed.

term to know

Database
A set of records contained within one or more tables.
Postgres
A free and open-source relational database management system.
The most common command to interact with a database is the SELECT statement to be able to query data from the tables. The most basic SELECT statement has the format of:

SELECT *
FROM <tablename>;

Where the <tablename> is replaced by the actual table’s name in the database. This statement is broken down into two clauses that must occur in that specific order. The SELECT clause indicates the columns to list in the specific order that they appear. The * is a unique wildcard that stands for ALL columns. Using this means that all the columns are selected to be displayed back to the user in the order that they appear in the table names that are listed. The second clause is the FROM clause that lists the table names that will be returned. For now, we will only focus on one table, but we will get into multiple table queries later on in the course.

term to know

SELECT
An SQL clause that retrieves zero or more rows of data from one or more database columns.
FROM
An SQL clause that identifies one or more tables as the source for a database query statement.
The data that is returned from a SELECT statement is stored in a result table called a result-set.

Keep in mind that SQL keywords are not case sensitive meaning that select is the same as Select or SELECT. Using uppercase keywords in uppercase is a best practice to visually separate out the keywords from the table or column names. However, it is not required.


2. Running A Query

Using the Postgres environment for this course, you can query the customer table by entering in:

SELECT *
FROM customer;

SQL query interface with schema browser
Entering a basic SQL query into the system.

Then click on the run/play button at the top right.

SQL interface play button
Use this button to run your SQL query.

This will execute the query and return the result set from the query. You should see that there are 59 rows of data. Each row is a unique record in the table customer. Each column name is listed along with the data associated with it below.

A example set of results from the SQL query including several columns and rows of information.
An example of SQL query results.

This is a useful start to be able to see all the data of a single table at one time.

try it
Your turn! Try a query in the SQL tool. You can start with the example above to see if you can replicate the results. Then feel free to try it on any of the other tables listed in the database on the left side of the SQL tool. To get started, press the LAUNCH DATABASE button below to open a new tab with the SQL tool.

Source: Author: Vincent Tran


3. Adding WHERE

The last main clause of the SELECT statement is the WHERE clause. The WHERE clause is used to filter records and only returns those rows/records when they fulfill a specific condition. We will be getting into many ways that we can filter data using the WHERE clause. Note that the WHERE clause is not only used in SELECT statements but also in other statements like the UPDATE and DELETE statements. We will cover these other statements in another lesson.

term to know

WHERE
An SQL clause that applies conditions to filter the result-set.
think about it
What might be some other things you’d want to ask that are not possible with only these three clauses?

summary
There are three main SQL clauses, SELECT, FROM, and WHERE. You can use them to form queries that display the desired data from a database. SELECT defines the columns to return from the table. FROM identifies the desired table. WHERE filters the data to meet your chosen conditions.