From the course: Intermediate SQL: Data Reporting and Analysis
The basic SELECT query - SQL Tutorial
From the course: Intermediate SQL: Data Reporting and Analysis
The basic SELECT query
- [Instructor] Students should already be familiar with the SELECT query, including filtering and sorting. In this chapter, we cover these concepts briefly as a refresher, as well as covering some functions we didn't see in the Reporting and Analysis course. In this video, we look at the structure of the SELECT query. The basic SELECT query looks like SELECT fields FROM table, WHERE filter, ORDER BY field ascending or descending. Let's have a look at the payment table. It has 16,049 rows. You can see that in the green bar towards the top of the screen. If we click Edit inline and run SELECT amount FROM payment WHERE payment date is less than 15th of June, you see that we return 1,173 rows. Note that I've used hyphens between the date parts here and double quotes around the date. So we have returned a single field and filtered for a reduced number of rows. We could also sort the results here with ORDER BY. If we just wanted to know the different amounts that have been charged without looking at every single transaction, we could run SELECT DISTINCT. And you can see now that we have just 12 rows returned, one for each of the different amounts in the database. Note that the WHERE filter can use and, or, and not to make the filter more complex. You may need to use parentheses to tell the database clearly what you're trying to achieve. So hopefully this SELECT statement is feeling familiar to you as we move on to more complex reporting.
Contents
-
-
-
-
The basic SELECT query1m 57s
-
(Locked)
Aggregated results with GROUP BY1m 51s
-
(Locked)
Wildcards and aliases6m
-
(Locked)
Merging tables with JOIN3m 56s
-
(Locked)
Use string functions8m 6s
-
(Locked)
Use number functions with grouped data6m 46s
-
(Locked)
Use date functions6m 7s
-
(Locked)
Challenge: Report average cost by staff53s
-
(Locked)
Solution: Report average cost by staff1m 49s
-
-
-
-
-