SQL and databases

Stage 2 · Lesson 1 of 8

SELECT, FROM, aliases and DISTINCT

Querying one table

Every read starts with , which lists the columns or calculations you want, and FROM, which names the table. Give a calculated column a clear name with AS, such as price * 0.9 AS sale_price. Give tables short aliases too (nicknames like c for customers), because you will need them once you join tables.

removes duplicate rows, comparing all the selected columns together. It answers questions like which countries have customers. In any query you save, name the columns you want.

SELECT * is fine for exploring, but it fetches data you do not need and breaks when someone adds a column.

Common trapusing DISTINCT to hide duplicates caused by a mistake, which you will meet again when joins multiply rows in the next stage.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking SQL for Tech Interviews

    Design Gurus · Intermediate · Subscription

    The basics, order of execution and functions chapters, each followed by graded problems

  • CourseFree
    SQLBolt

    SQLBolt · Beginner

    Free: Lessons 1 to 4, 8, 9 and 12 cover SELECT, filtering, sorting, NULLs, expressions and query order

Practise

Keep handy

  • The T-SQL SELECT, TOP and ORDER BY pages and the date and time functions list

  • Its SQL pages give quick examples and note where MySQL and SQL Server syntax differ

Also worth your time

Mark this stage as not done?