Online College Courses for Credit

+
1 Tutorials that teach SELECT to Display Data
Take your pick:
SELECT to Display Data

SELECT to Display Data

Rating:
(0)
Author: Sophia Tutorial
Description:

Identify a SELECT statement that will display one or more columns of data.

(more)
See More
Tutorial

what's covered
This tutorial shows how to limit your results to only the columns of information you desire, covering how to write a SQL query that displays only your chosen columns in the results:
  1. Using SELECT to Display Data

1. Using SELECT to Display Data

There are instances where you may not need to see all the data at one time. For example, you may want to just see the customer’s email address to send out a marketing campaign email. To select only email addresses, instead of using the *, we can list out the column that we would like to display. Looking at the column list under the schema browser, we can see the list of columns:

File:11550-image1.png

The eighth column contains the email addresses that we want to display. Using the SELECT statement, we can alter the SELECT clause to display just the email addresses instead of all columns by replacing the * with the specific column name. The query statement would be changed to:

SELECT email FROM customer;

Running this statement displays only email addresses:

File:11551-image2.png

This is useful, but perhaps we would like to also include their first and last name. If we want to select more than one column, we need to separate out the column list using commas. For example:

SELECT first_name, last_name, email FROM customer;

This would return the result set that looks like the following:

File:11552-image3.png

You can switch the column list in any order that you would like displayed:

SELECT email, last_name, first_name FROM customer;

File:11553-image5.png

You could even have the same column twice:

SELECT email, email FROM customer;

This query returns:

File:11554-image4.png

This may not appear useful now, but when we focus on calculations in SELECT statements, we will revisit the purpose of having columns listed more than once.

Source: Vincent Tran

try it
Your turn! Open the SQL tool by clicking on the LAUNCH DATABASE button below. Then enter in one of the examples above and see how it works. Next, try your own choices for which columns you want the query to provide.

term to know

Schema Browser
A list of table names, column names, and data types contained within a database.
summary
In this tutorial, you learned how to write a SELECT statement to choose specific columns from your database table and display that information in the results.