• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 3 fuera de 27 páginas
Otro

SQL Queries Handbook | 100 Most Used Queries for Exam & Interview Prep

Document preview thumbnail
Vista previa 3 fuera de 27 páginas

Master relational databases with this comprehensive SQL Queries Handbook, featuring the 100 most frequently used queries across production, exams, and technical interviews! Whether you are preparing for a university Database Management Systems (DBMS) final exam, brushing up before a software engineering interview, or looking for a clean quick-revision guide, this document has you covered. It features full cross-compatibility notes highlighting syntax variations across MySQL, PostgreSQL, SQL Server, Oracle, and SQLite. Inside the Handbook: Section 1: SELECT & Filtering Basics – Explicit columns, WHERE, AND/OR precedence, DISTINCT, sorting with ORDER BY, pagination (LIMIT/OFFSET), range filters (BETWEEN), and wildcard pattern matching (LIKE). Section 2: Aggregate Functions & GROUP BY – Comprehensive guides to COUNT, SUM, AVG, MIN, MAX, grouping combinations, and generating automated subtotals/grand totals via ROLLUP and GROUPING SETS. Section 3: Combining Tables (JOINs) – Master INNER JOIN, LEFT/RIGHT OUTER JOIN, FULL OUTER JOIN solutions for MySQL, CROSS JOIN, Self Joins, and high-performance Anti Joins. Section 4: Subqueries & CTEs – In-depth usage of WHERE/FROM/SELECT subqueries, EXISTS vs. IN clauses, Correlated subqueries, and complex multi-chain or Recursive Common Table Expressions (CTEs). Section 5: Window Functions – Core analytical functions including ROW_NUMBER(), RANK(), DENSE_RANK(), calculating running totals or moving averages, and period-over-period row shifting using LAG() and LEAD(). Section 6: Built-in Functions – String manipulation (CONCAT, SUBSTRING, TRIM, padding), conditional logic (CASE WHEN), date arithmetic, type conversion (CAST), and safety functions like COALESCE or NULLIF to prevent division-by-zero errors. Section 7 & 8: DML & DDL (Schema Management) – Row modification workflows (INSERT, UPDATE with JOINs, DELETE vs. TRUNCATE), advanced UPSERT/MERGE queries, creating tables with strict data constraints (FOREIGN KEY CASCADE, CHECK), and database view design. Section 9 & 10: Transactions & Advanced Interview Classics – Understanding transactional ACID integrity (BEGIN, COMMIT, ROLLBACK, SAVEPOINT), optimizing querying performance using composite/unique INDEXES with EXPLAIN execution plans, implementing stored procedures, and resolving classic interview patterns (deduplicating tables, pivoting rows-to-columns). Includes a clean Quick Reference Cheat-Sheet summarizing the core execution rules and primary purposes of every major SQL clause at a single glance!

Vista previa del contenido

SQL

Queries Handbook

100 Most Used Queries




■ SELECT & Filtering ■ JOINs ■ Aggregates



■ Subqueries ■ Window Functions ■ DDL & DML



■ Indexes & Views ■ Stored Procedures ■ Transactions




Exam Prep · Interview Ready · Quick Revision



Covers: MySQL · PostgreSQL · SQL Server · Oracle · SQLite syntax with notes on differences

,SQL Queries Handbook | 100 Most Used Queries Page 2




■ Section 1 — SELECT & Filtering Basics

#001
Select All Columns
Retrieve every column and row from a table. Use sparingly in production — fetching unused columns wastes
bandwidth.
SELECT *
FROM employees;
✎ Prefer listing explicit columns in production code. SELECT * is fine for quick exploration.

#002
Select Specific Columns
Retrieve only the columns you need — faster and cleaner.
SELECT first_name, last_name, salary
FROM employees;

#003
Filter with WHERE
Return only rows that match a condition.
SELECT *
FROM employees
WHERE department = 'Engineering';

#004
Multiple Conditions with AND / OR
Combine filters. AND requires both conditions; OR requires at least one.
SELECT *
FROM employees
WHERE department = 'Sales'
AND salary > 50000;
✎ Wrap OR conditions in parentheses to avoid precedence bugs: WHERE a AND (b OR c).

#005
NOT Operator
Exclude rows matching a condition.
SELECT *
FROM employees
WHERE NOT department = 'HR';

#006
DISTINCT — Remove Duplicates
Return unique values only.
SELECT DISTINCT department
FROM employees;
✎ DISTINCT applies across all selected columns, not just the first one.




Exam Prep · Interview Cracker · Quick Reference

, SQL Queries Handbook | 100 Most Used Queries Page 3




#007
ORDER BY — Sort Results
Sort results ascending (default) or descending.
SELECT first_name, salary
FROM employees
ORDER BY salary DESC;

#008
LIMIT / TOP — Restrict Rows
Return only the first N rows. Syntax varies by database.
-- MySQL / PostgreSQL / SQLite
SELECT * FROM employees LIMIT 10;
-- SQL Server
SELECT TOP 10 * FROM employees;
-- Oracle
SELECT * FROM employees WHERE ROWNUM <= 10;

#009
OFFSET — Pagination
Skip N rows before returning results. Combined with LIMIT for page-based results.
SELECT *
FROM employees
ORDER BY employee_id
LIMIT 10 OFFSET 20; -- page 3 (rows 21-30)
✎ Always include ORDER BY with OFFSET — without it, the 'skipped' rows are undefined.

#010
BETWEEN — Range Filter
Filter rows where a column value falls within an inclusive range.
SELECT *
FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31';
✎ BETWEEN is inclusive on both ends — equivalent to col >= low AND col <= high.

#011
IN — Match a List
Filter rows where a column matches any value in a list.
SELECT *
FROM employees
WHERE department IN ('Sales', 'Marketing', 'HR');

#012
NOT IN
Exclude rows matching any value in a list. Beware NULL values in the list — NOT IN returns no rows if the list
contains NULL.
SELECT *
FROM employees
WHERE department NOT IN ('Finance', 'Legal');
✎ If the subquery can return NULL, prefer NOT EXISTS over NOT IN.




Exam Prep · Interview Cracker · Quick Reference

Información del documento

Subido en
14 de junio de 2026
Número de páginas
27
Escrito en
2025/2026
Tipo
Otro
Personaje
Desconocido
$8.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
3
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes