Loading lesson...
Your first SQL query starts here
Your first SQL query — demystified
Topics covered: Tables, rows, and columns, SELECT and FROM basics, Selecting all columns (*), AS aliases for columns, Expressions in SELECT
Inside each table in a database, information is organized into rows and columns. A row is a single record, such as one person, one order, or one product. A column is a type of information stored for every record, such as a name, a price, or a date. A cell is a single value, such as the name 'John' or the date 2025-10-12. Together, the rows and columns form a grid of cells much like a spreadsheet. You can look across a row to see all the details for one record, or down a column to see that type o
Every SQL query follows a predictable structure that tells the database what data you want and where to find it. Building Your First Query Understanding the role of each keyword helps you construct queries that retrieve exactly the data you need. SELECT Columns FROM Arrange the Query Check Your Understanding Selecting only the columns you need, rather than all columns, reduces the amount of data the database must read and transfer, which makes queries faster on large tables.
The asterisk symbol provides a quick way to retrieve all columns without typing each name individually. When to Use * Choosing the Right Columns Now try selecting different columns from a product inventory table. Requesting only the columns relevant to your question means analysts reading your query can immediately understand what data you care about without scrolling through irrelevant output. The ability to select any combination of columns from a table is one of the core reasons SQL is so fle
Aliases let you create readable, descriptive names for columns and tables without changing the underlying data. When you use an alias, the underlying table and its data remain unchanged. The alias only affects how the data is labeled in your query and results. Toggle between the examples below to see each type. Practical Aliasing Production databases often have column names like usr_cre_dt or prc_usd_base that save keystrokes when engineers build the schema but confuse everyone reading queries l
Expressions transform data on the fly, letting you compute totals, differences, and other derived values directly in your query. An expression is any combination of values, operators, and functions that the database evaluates to produce a result. For example, "price + tax" is an expression that adds two column values together. SQL can calculate new values as part of the results using expressions. Common Operations SQL supports standard arithmetic operators that let you perform calculations direc