2.PracticalSQL2E_SampleCh3 - Copy
2.PracticalSQL2E_SampleCh3 - Copy
This single line of code shows the most basic form of a SQL query. The
asterisk following the SELECT keyword is a wildcard, which is like a stand-in
for a value: it doesn’t represent anything in particular and instead repre-
sents everything that value could possibly be. Here, it’s shorthand for “select
all columns.” If you had given a column name instead of the wildcard,
this command would select the values in that column. The FROM keyword
indicates you want the query to return data from a particular table. The
semicolon after the table name tells PostgreSQL it’s the end of the query
statement.
Let’s use this SELECT statement with the asterisk wildcard on the teach-
ers table you created in Chapter 2. Once again, open pgAdmin, select the
analysis database, and open the Query Tool. Then execute the statement
shown in Listing 3-1. Remember, as an alternative to typing these state-
ments into the Query Tool, you can also run the code by clicking Open File
and navigating to the place where you saved the code you downloaded from
GitHub. Always do this if you see the code is truncated with --snip--. For
this chapter, you should open Chapter_03.sql and highlight each statement
before clicking the Execute/Refresh icon.
Listing 3-1: Querying all rows and columns from the teachers table
Once you execute the query, the result set in the Query Tool’s output
pane contains all the rows and columns you inserted into the teachers table
in Chapter 2. The rows may not always appear in this order, but that’s okay.
2 Chapter 3