Loading topic
EXISTS build on one idea: a query nested inside the WHERE clause of another query. This chapter reviews that idea so the later chapters can add to it. You will see the shapes of subquery results, the operators that accept them, and the errors people hit most often. Ever7 min readEXISTS query, as covered in the previous chapters. You should also know what a correlated subquery is and how table aliases work. Here you will learn why EXISTS (SELECT 1 ...), EXISTS (SELECT * ...) and EXISTS (SELECT NULL ...) all behave the same w6 min readSELECT and WHERE queries, use INNER JOIN and LEFT JOIN, and read table aliases. It also assumes you know that NULL means a missing value, and you have seen the correlated subquery and EXISTS from the earlier chapters. Here you will use NOT EXISTS to a6 min readWHERE and that you know what a correlated subquery is: an inner query that refers to a column of the outer row. It also assumes you know that NULL means a missing value. The examples use customers, orders, order_items, and products.6 min readINNER JOIN and LEFT JOIN, use DISTINCT and GROUP BY, and read EXISTS and NOT EXISTS queries. It also assumes you know that a comparison with NULL evaluates to UNKNOWN, not true. We use the same customers, orders, order_items, and products tabl8 min readEXISTS, and NOT EXISTS, and which indexes make them fast. It assumes you can write EXISTS and NOT EXISTS queries, know INNER JOIN and LEFT JOIN, and can read a basic query plan. The examples use the customers, `orders7 min readEXISTS and NOT EXISTS in UPDATE and DELETE statements. It assumes you can write a correlated subquery and use EXISTS and NOT EXISTS in a SELECT. You should also know basic transaction commands (START TRANSACTION, COMMIT, ROLLBACK). The examples use t7 min readFOR ALL operator, but you can express the idea with two nested NOT EXISTS tests. This chapter shows how to read and write that pattern, where it goes wrong, and how it compares with a counting approach.7 min read