Lesson 4 – Selecting Records from Tables

In the previous lesson, you saw how to insert records in a table, in this lesson you will see how to retrieve records from a table. To select records, we can use the SELECT query. Let’s select all the records from the “products” table. Note that before executing the following query inside the “Execute SQL” tab.

SELECT * FROM products

To select the data from all the columns in your table, you have to specify the SELECT keyword followed by asterisk ‘*’ symbol. Next, you have to specify FROM followed by the name of your table, when you execute the above script, you will see records from all the columns in the “products” table as shown below:

To select records from specific columns, you can write the names of the column after the SELECT clause. For instance, if you want to only SELECT the data from the “name” and “price” columns, you can do so with the following query:

SELECT name, price FROM products

In the output, you will see the following results:

You can see that the result now only contains the data from the name and price columns.

In the case of longer queries, you can split your queries into multiple lines. For instance, the following two queries will return the same results:

Query1

SELECT name, price 
 FROM products

Query2

SELECT name, price FROM products

Finally, let’s select all the records from the “categories” table. Look at the following script:


SELECT * from categories

Here is the output screenshot:

What’s Next?

In this lesson, you saw how to select data. In the next lesson, you will see how to filter data using the WHERE clause. You will see things like how to execute queries that SELECT products with price greater than a certain number and so on.