On Day 3 you learned how to build tables, define schemas and choose the right data types. Today, we begin querying that data with the SELECT statement, the cornerstone of every SQL query. This lesson will show you how to retrieve rows and columns from your database, explain the key clauses of a SELECT query, and illustrate the logical processing order with a custom diagram.
What Does SELECT Do?
The SELECT
statement retrieves rows from the database and allows you to choose one or more columns from one or more tables While its full syntax can become complicated, a basic query includes a few optional clauses:
SELECT – choose the columns you want to return.
FROM – specify the table(s) you are querying.
WHERE – filter rows based on a condition.
GROUP BY – group rows to perform aggregations.
HAVING – filter groups after aggregation.
ORDER BY – sort the results.
These clauses must appear in the proper order when used.
Logical Processing Order
Although you write queries starting with SELECT
, the SQL engine processes the clauses in a different order. Understanding this sequence helps you avoid mistakes. Microsoft’s documentation lists the logical order as follows:
FROM
ON
JOIN
WHERE
GROUP BY
HAVING
SELECT
DISTINCT
ORDER BY
TOP/LIMIT
The diagram below visualises this sequence, showing that the FROM
clause binds the tables before any filtering or grouping occurs:
Basic SQL Examples
Say we have a table called books with the following columns (title, author, pages)
To select everything from that table you’d use:
SELECT * FROM books;
This query returns all records in the table and the * is shorthand for “all columns”.
To retrieve specific columns from the table you’d use:
SELECT title, pages FROM books;
This returns all records in the table but only the title and pages columns. Not the author column.
To retrieve only certain records in the table you’d use:
SELECT title, pages
FROM books
WHERE pages > 100
The where clause evaluates each row and returns only those that match the condition.
To sort results by a column you’d use:
SELECT *
FROM books
ORDER BY pages DESC
The above sorts the results by page count in descending order.
What’s Next?
In day 5, we’ll dig deeper into the where clause and learn how to filter rows using comparison, logical and pattern‑matching operators. Keep experimenting with your own data, SQL skills are built through repetition and curiosity!
i now have a dataflow item in my named workspace, at the root along with the challenge schema. Now I should do what?
Alternatively, how do i create rows with data in my challenge.daily_tasks table?
I am trying to import data into my challenge schema. I tried get dsta, new dataflow gen, and browsed to a xlsx in one drive.