Loading topic
SELECT list does more than name columns. Each item in it is an expression, and the database evaluates that expression once for every row the query produces. This chapter covers what an expression is, how SQL evaluates it, and the errors that come up most often. Later chapters cover operators, fu6 min readSELECT ... FROM ... WHERE queries and know the common column types (numbers, text, dates). The examples use an employees table with first_name, last_name, salary, commission, and department_id. They run as written on PostgreSQL. The chapter poin6 min readSELECT ... FROM ... WHERE queries and know the basic column types: numbers, text and dates. It also assumes you have seen the arithmetic and comparison operators from the previous chapter. Examples use an employees table with employee_id, first_name, `last_5 min readSELECT ... FROM ... WHERE queries, know the common column types (numbers, text, dates), and have used GROUP BY with COUNT and SUM. It covers how NULL moves through arithmetic, string operations, comparisons, and boolean logic, and the mistakes that 6 min readSELECT ... FROM ... WHERE queries and know the common column types. It also assumes you know that NULL means "unknown or missing", and that arithmetic on NULL returns NULL. The previous chapter covered those rules. This chapter covers the two standard5 min readSELECT ... FROM ... WHERE queries and know the common column types. It also assumes you know what GROUP BY does. You have already seen that the SELECT list can hold computed expressions. Here you learn how to give each result column a name, and which rule6 min readSELECT ... FROM ... WHERE queries and use GROUP BY with aggregates such as COUNT and SUM. It also assumes you know how to name a computed column with AS. The question here is where that name is visible. If you get this wrong, you see errors like `column "5 min readSELECT ... FROM ... WHERE queries, know the common column types (numbers, text, dates), and understand GROUP BY with aggregates like COUNT and SUM. It also assumes you have seen computed columns and aliases earlier in the tutorial, such as `salary * 16 min readSELECT ... FROM ... WHERE query and know common column types such as numbers, text, and dates. It also assumes you have seen the searched CASE form (CASE WHEN condition THEN result) from the previous chapter. Here you will learn the second form, the s6 min readCASE expressions, know that NULL means "unknown", and have used COALESCE. Here you will learn the rules that decide which branch CASE returns and what data type the result has. Most CASE bugs come from three things: branches in the wro6 min readCASE expression, how NULL behaves in comparisons, and how column aliases are scoped. It also assumes you can write a basic GROUP BY query. The examples use two tables: `employees(employeeid, firstname, last_name, salary, commiss6 min readSELECT ... FROM ... WHERE queries and use GROUP BY with COUNT and SUM. It also assumes you know how a searched CASE expression picks its result, and that NULL means "unknown" and is not equal to anything. The examples use an employees table with7 min readAS, and write CASE expressions. It covers how SQL converts values from one type to another, where that conversion produces surprises, and where the major databases (PostgreSQL, MySQL, SQL Server,6 min read