Chapter 13: SQL Basics
13.3 Selecting Data from Tables
Now that we have some data in our table, we can retrieve it using the SELECT
statement. Here's how to retrieve all data from the 'Books' table:
SELECT * FROM Books;
The *
symbol is a wildcard that means "all columns". This statement will return every row from every column in the 'Books' table. The output would be:
+--------+----------------------+----------------------+-------+
| BookID | Title | Author | Price |
+--------+----------------------+----------------------+-------+
| 1 | To Kill a Mockingbird| Harper Lee | 7.99 |
| 2 | 1984 | George Orwell | 8.99 |
| 3 | The Great Gatsby | F. Scott Fitzgerald | 6.99 |
+--------+----------------------+----------------------+-------+
If we only want to select data from certain columns, we can specify those columns instead of using *
. For example, to select only the 'Title' and 'Author' columns, we can use the following statement:
SELECT Title, Author FROM Books;
This will return:
+----------------------+----------------------+
| Title | Author |
+----------------------+----------------------+
| To Kill a Mockingbird| Harper Lee |
| 1984 | George Orwell |
| The Great Gatsby | F. Scott Fitzgerald |
+----------------------+----------------------+
The SELECT
statement can be used with a variety of clauses to filter and sort the returned data, which we'll explore more in the following sections. For now, try creating your own tables, inserting data, and selecting data. This will solidify your understanding of these fundamental SQL operations.
13.3 Selecting Data from Tables
Now that we have some data in our table, we can retrieve it using the SELECT
statement. Here's how to retrieve all data from the 'Books' table:
SELECT * FROM Books;
The *
symbol is a wildcard that means "all columns". This statement will return every row from every column in the 'Books' table. The output would be:
+--------+----------------------+----------------------+-------+
| BookID | Title | Author | Price |
+--------+----------------------+----------------------+-------+
| 1 | To Kill a Mockingbird| Harper Lee | 7.99 |
| 2 | 1984 | George Orwell | 8.99 |
| 3 | The Great Gatsby | F. Scott Fitzgerald | 6.99 |
+--------+----------------------+----------------------+-------+
If we only want to select data from certain columns, we can specify those columns instead of using *
. For example, to select only the 'Title' and 'Author' columns, we can use the following statement:
SELECT Title, Author FROM Books;
This will return:
+----------------------+----------------------+
| Title | Author |
+----------------------+----------------------+
| To Kill a Mockingbird| Harper Lee |
| 1984 | George Orwell |
| The Great Gatsby | F. Scott Fitzgerald |
+----------------------+----------------------+
The SELECT
statement can be used with a variety of clauses to filter and sort the returned data, which we'll explore more in the following sections. For now, try creating your own tables, inserting data, and selecting data. This will solidify your understanding of these fundamental SQL operations.
13.3 Selecting Data from Tables
Now that we have some data in our table, we can retrieve it using the SELECT
statement. Here's how to retrieve all data from the 'Books' table:
SELECT * FROM Books;
The *
symbol is a wildcard that means "all columns". This statement will return every row from every column in the 'Books' table. The output would be:
+--------+----------------------+----------------------+-------+
| BookID | Title | Author | Price |
+--------+----------------------+----------------------+-------+
| 1 | To Kill a Mockingbird| Harper Lee | 7.99 |
| 2 | 1984 | George Orwell | 8.99 |
| 3 | The Great Gatsby | F. Scott Fitzgerald | 6.99 |
+--------+----------------------+----------------------+-------+
If we only want to select data from certain columns, we can specify those columns instead of using *
. For example, to select only the 'Title' and 'Author' columns, we can use the following statement:
SELECT Title, Author FROM Books;
This will return:
+----------------------+----------------------+
| Title | Author |
+----------------------+----------------------+
| To Kill a Mockingbird| Harper Lee |
| 1984 | George Orwell |
| The Great Gatsby | F. Scott Fitzgerald |
+----------------------+----------------------+
The SELECT
statement can be used with a variety of clauses to filter and sort the returned data, which we'll explore more in the following sections. For now, try creating your own tables, inserting data, and selecting data. This will solidify your understanding of these fundamental SQL operations.
13.3 Selecting Data from Tables
Now that we have some data in our table, we can retrieve it using the SELECT
statement. Here's how to retrieve all data from the 'Books' table:
SELECT * FROM Books;
The *
symbol is a wildcard that means "all columns". This statement will return every row from every column in the 'Books' table. The output would be:
+--------+----------------------+----------------------+-------+
| BookID | Title | Author | Price |
+--------+----------------------+----------------------+-------+
| 1 | To Kill a Mockingbird| Harper Lee | 7.99 |
| 2 | 1984 | George Orwell | 8.99 |
| 3 | The Great Gatsby | F. Scott Fitzgerald | 6.99 |
+--------+----------------------+----------------------+-------+
If we only want to select data from certain columns, we can specify those columns instead of using *
. For example, to select only the 'Title' and 'Author' columns, we can use the following statement:
SELECT Title, Author FROM Books;
This will return:
+----------------------+----------------------+
| Title | Author |
+----------------------+----------------------+
| To Kill a Mockingbird| Harper Lee |
| 1984 | George Orwell |
| The Great Gatsby | F. Scott Fitzgerald |
+----------------------+----------------------+
The SELECT
statement can be used with a variety of clauses to filter and sort the returned data, which we'll explore more in the following sections. For now, try creating your own tables, inserting data, and selecting data. This will solidify your understanding of these fundamental SQL operations.