02
Chapter 2
Basic SELECT
The foundation. Selecting columns, ordering, limiting, and counting — the vocabulary every query is built from.
In this chapter
136
queries, easy → advanced
- 001Select all columns from employees tableRead
- 002Select specific columns: first_name, last_name, salaryRead
- 003Select distinct job titles from employeesRead
- 004Select top 10 highest paid employeesRead
- 005Count total number of employeesRead
- 006Find maximum, minimum, and average salaryRead
- 007Select employees with column aliasesRead
- 008Select all departments and their locationsRead
- 009Count employees in each department (just count)Read
- 010Select first 5 products by price descendingRead
- 011Select all active employeesRead
- 012Show total sum of all product prices in stockRead
- 013Select employees hired in the year 2023Read
- 014Show products with stock between 10 and 100Read
- 015Select customers from India or USARead
- 016Select all orders with NULL shipped_at (not shipped)Read
- 017Show total revenue from all ordersRead
- 018List all unique countries from customersRead
- 019Get 2nd page of employees (OFFSET pagination)Read
- 020Show employee salaries with a 10% bonus calculationRead
- 021Select employees using CASE to label salary bracketsRead
- 022Show products with profit margin percentageRead
- 023Select all employees and their years of experienceRead
- 024Show department-wise headcount and average salaryRead
- 025Select employees using NULLIF to avoid division by zeroRead
- 026Show all employees sorted by hire date newest firstRead
- 027Show all products with their category id sorted by priceRead
- 028Count distinct departments in employees tableRead
- 029Show employees hired this yearRead
- 030Show total, average salary across entire companyRead
- 031List all projects with their status and budgetRead
- 032Find employees with salary NULLRead
- 033Show customers grouped by country with countRead
- 034Show top 5 most expensive products per categoryRead
- 035Conditional count: active vs inactive employeesRead
- 036FETCH FIRST: SQL standard alternative to LIMITRead
- 037Create a basic table with primary keyRead
- 038Create table with IF NOT EXISTSRead
- 039Add a new column to an existing tableRead
- 040Rename a columnRead
- 041Change column data typeRead
- 042Drop a columnRead
- 043Rename an entire tableRead
- 044Create table using AS (CTAS)Read
- 045Create table LIKE another tableRead
- 046Drop table safelyRead
- 047Empty a table quicklyRead
- 048Add a NOT NULL constraintRead
- 049Remove a NOT NULL constraintRead
- 050Add a DEFAULT value to a columnRead
- 051Add a UNIQUE constraintRead
- 052Add a FOREIGN KEY constraintRead
- 053Add a CHECK constraintRead
- 054Multi-column UNIQUE constraintRead
- 055Add constraint NOT VALID (for large tables)Read
- 056Drop a constraintRead
- 057Cast data types using :: syntaxRead
- 058Cast data types using CAST() standardRead
- 059Array data typesRead
- 060Querying Array columnsRead
- 061Using UUIDsRead
- 062JSONB Data TypeRead
- 063Querying JSONB propertiesRead
- 064ENUM Data TypeRead
- 065Create a custom SequenceRead
- 066Use a SequenceRead
- 067DDL Practice: Create table variant #1Read
- 068Constraint Practice: Add CHECK constraint variant #1Read
- 069DDL Practice: Create table variant #2Read
- 070Constraint Practice: Add CHECK constraint variant #2Read
- 071DDL Practice: Create table variant #3Read
- 072Constraint Practice: Add CHECK constraint variant #3Read
- 073DDL Practice: Create table variant #4Read
- 074Constraint Practice: Add CHECK constraint variant #4Read
- 075DDL Practice: Create table variant #5Read
- 076Constraint Practice: Add CHECK constraint variant #5Read
- 077DDL Practice: Create table variant #6Read
- 078Constraint Practice: Add CHECK constraint variant #6Read
- 079DDL Practice: Create table variant #7Read
- 080Constraint Practice: Add CHECK constraint variant #7Read
- 081DDL Practice: Create table variant #8Read
- 082Constraint Practice: Add CHECK constraint variant #8Read
- 083DDL Practice: Create table variant #9Read
- 084Constraint Practice: Add CHECK constraint variant #9Read
- 085DDL Practice: Create table variant #10Read
- 086Constraint Practice: Add CHECK constraint variant #10Read
- 087DDL Practice: Create table variant #11Read
- 088Constraint Practice: Add CHECK constraint variant #11Read
- 089DDL Practice: Create table variant #12Read
- 090Constraint Practice: Add CHECK constraint variant #12Read
- 091DDL Practice: Create table variant #13Read
- 092Constraint Practice: Add CHECK constraint variant #13Read
- 093DDL Practice: Create table variant #14Read
- 094Constraint Practice: Add CHECK constraint variant #14Read
- 095DDL Practice: Create table variant #15Read
- 096Constraint Practice: Add CHECK constraint variant #15Read
- 097DDL Practice: Create table variant #16Read
- 098Constraint Practice: Add CHECK constraint variant #16Read
- 099DDL Practice: Create table variant #17Read
- 100Constraint Practice: Add CHECK constraint variant #17Read
- 101DDL Practice: Create table variant #18Read
- 102Constraint Practice: Add CHECK constraint variant #18Read
- 103DDL Practice: Create table variant #19Read
- 104Constraint Practice: Add CHECK constraint variant #19Read
- 105DDL Practice: Create table variant #20Read
- 106Constraint Practice: Add CHECK constraint variant #20Read
- 107DDL Practice: Create table variant #21Read
- 108Constraint Practice: Add CHECK constraint variant #21Read
- 109DDL Practice: Create table variant #22Read
- 110Constraint Practice: Add CHECK constraint variant #22Read
- 111DDL Practice: Create table variant #23Read
- 112Constraint Practice: Add CHECK constraint variant #23Read
- 113DDL Practice: Create table variant #24Read
- 114Constraint Practice: Add CHECK constraint variant #24Read
- 115DDL Practice: Create table variant #25Read
- 116Constraint Practice: Add CHECK constraint variant #25Read
- 117DDL Practice: Create table variant #26Read
- 118Constraint Practice: Add CHECK constraint variant #26Read
- 119DDL Practice: Create table variant #27Read
- 120Constraint Practice: Add CHECK constraint variant #27Read
- 121DDL Practice: Create table variant #28Read
- 122Constraint Practice: Add CHECK constraint variant #28Read
- 123DDL Practice: Create table variant #29Read
- 124Constraint Practice: Add CHECK constraint variant #29Read
- 125DDL Practice: Create table variant #30Read
- 126Constraint Practice: Add CHECK constraint variant #30Read
- 127DDL Practice: Create table variant #31Read
- 128Constraint Practice: Add CHECK constraint variant #31Read
- 129DDL Practice: Create table variant #32Read
- 130Constraint Practice: Add CHECK constraint variant #32Read
- 131DDL Practice: Create table variant #33Read
- 132Constraint Practice: Add CHECK constraint variant #33Read
- 133DDL Practice: Create table variant #34Read
- 134Constraint Practice: Add CHECK constraint variant #34Read
- 135DDL Practice: Create table variant #35Read
- 136Constraint Practice: Add CHECK constraint variant #35Read