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.
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.
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.
Using the Postgres environment for this course, you can query the customer table by entering in:
SELECT *
FROM customer;
Then click on the run/play button at the top right.
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.
This is a useful start to be able to see all the data of a single table at one time.
Source: Author: Vincent Tran
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.