{"appId":"sql-app","version":1551,"selectedAngularVersion":20,"item":{"id":"lesson-what-is-sql","conceptKey":"what-is-sql","subjectId":"subject-what-is-sql","title":"What is SQL?","summary":"SQL is the declarative language used to define, query, change, and control data in relational databases.","baseContent":"<h2>What is SQL?</h2><p>SQL is the declarative language used to define, query, change, and control data in relational databases.</p><h3>Example</h3><pre><code>SELECT name, price\nFROM products\nWHERE price &lt; 100;</code></pre><h3>Key point</h3><p>Use the smallest correct statement, test it with representative data, and verify constraints and performance before production use.</p><h3>Real-life example</h3><p>A development team applies What is SQL? to a small commerce database, verifies the result, and then decides whether the same approach is safe for production data.</p><h3>Advanced example</h3><pre><code>BEGIN;\n-- Preview the exact target set first.\nSELECT id FROM orders WHERE status = 'pending';\n-- Apply the What is SQL? operation, verify affected rows, then commit.\nCOMMIT;</code></pre><h3>Expected result</h3><p>The schema or operation satisfies the stated rule, rejects invalid data, and can be verified with a repeatable query.</p><h3>Production check</h3><ul><li>Test with empty, duplicate, null, and boundary values.</li><li>Use a transaction for related writes.</li><li>Inspect the execution plan before adding an index.</li><li>Use parameterized queries for application input.</li></ul><h3>Continue with the PicoStore database</h3><p>This lesson reuses <strong>picostore</strong>. Relevant tables: <code>customers, products, orders, order_items</code>. Keep the starter rows from the Introduction lesson so results remain comparable.</p><h3>Another practical example</h3><pre><code>SELECT o.order_id, c.name AS customer, o.status, o.total\nFROM orders o\nJOIN customers c ON c.customer_id = o.customer_id\nWHERE o.total &gt;= 1000\nORDER BY o.ordered_at DESC;</code></pre><h3>Check the result</h3><p>Run the verification query, compare the returned rows with the starter data, and explain why every included or excluded row is correct.</p><section data-sql-reference-catalog=\"true\"><h2>SQL reference catalog: What is SQL?</h2><p>This catalog covers the practical public SQL surface. Check the exact server-version documentation before using a vendor-specific item.</p><h3>SQL command families</h3><ul><li><code>DQL</code> — SELECT queries data</li><li><code>DDL</code> — CREATE, ALTER, DROP, TRUNCATE, RENAME define structures</li><li><code>DML</code> — INSERT, UPDATE, DELETE, MERGE change rows</li><li><code>DCL</code> — GRANT and REVOKE control access</li><li><code>TCL</code> — BEGIN, COMMIT, ROLLBACK, SAVEPOINT control transactions</li></ul><h3>Core query clauses in logical order</h3><ul><li><code>WITH</code> — defines common table expressions</li><li><code>SELECT</code> — chooses expressions and columns</li><li><code>FROM</code> — chooses source tables</li><li><code>JOIN ... ON</code> — combines related sources</li><li><code>WHERE</code> — filters rows before grouping</li><li><code>GROUP BY</code> — forms groups</li><li><code>HAVING</code> — filters groups</li><li><code>WINDOW</code> — names reusable window definitions</li><li><code>ORDER BY</code> — sorts the result</li><li><code>LIMIT / OFFSET or FETCH</code> — restricts returned rows</li></ul></section><section data-nonversioned-curriculum=\"1\"><h3>Easy example</h3><p>Start with a small customer table and retrieve active customers in a predictable order.</p><pre><code>SELECT customer_id, name, email\nFROM customers\nWHERE status = 'active'\nORDER BY name;</code></pre><h3>How to verify the easy example</h3><ul><li>Run it with representative input.</li><li>Confirm the expected output.</li><li>Try one missing, invalid, or boundary value.</li></ul><h3>Advanced example</h3><p>Use a CTE and a window function to rank customer revenue while keeping the query readable and testable.</p><pre><code>WITH customer_revenue AS (\n  SELECT customer_id, SUM(total_amount) AS revenue\n  FROM orders\n  WHERE order_status = 'completed'\n  GROUP BY customer_id\n)\nSELECT customer_id, revenue,\n       DENSE_RANK() OVER (ORDER BY revenue DESC) AS revenue_rank\nFROM customer_revenue\nORDER BY revenue_rank, customer_id;</code></pre><h3>Advanced review</h3><ul><li>Explain the tradeoffs and assumptions.</li><li>Test failure, scale, security, and recovery behavior.</li><li>Capture evidence from tests, execution plans, logs, or review output.</li></ul><h3>Additional practical guidance</h3><div><h3>What is SQL?: MySQL and PostgreSQL</h3><p>Use standard SQL first, then document any MySQL or PostgreSQL-specific syntax. Verify the statement with small sample data, an edge case, and the expected result before using it in production.</p><h3>Required verification</h3><ul><li>Run the simple case.</li><li>Test a NULL, duplicate, empty, or boundary case where relevant.</li><li>Confirm the affected rows or query result.</li><li>Use EXPLAIN for performance-sensitive queries.</li></ul></div></section>","detailId":"lesson-what-is-sql-660db64a","versions":[],"isActive":true,"detailIsActive":true,"lessonVersions":[],"selectedVersion":20,"content":"","updatedAt":"2026-08-01T09:43:04.474Z","details":[{"id":"lesson-what-is-sql","conceptKey":"what-is-sql","subjectId":"subject-what-is-sql","title":"What is SQL?","summary":"SQL is the declarative language used to define, query, change, and control data in relational databases.","baseContent":"<h2>What is SQL?</h2><p>SQL is the declarative language used to define, query, change, and control data in relational databases.</p><h3>Example</h3><pre><code>SELECT name, price\nFROM products\nWHERE price &lt; 100;</code></pre><h3>Key point</h3><p>Use the smallest correct statement, test it with representative data, and verify constraints and performance before production use.</p><h3>Real-life example</h3><p>A development team applies What is SQL? to a small commerce database, verifies the result, and then decides whether the same approach is safe for production data.</p><h3>Advanced example</h3><pre><code>BEGIN;\n-- Preview the exact target set first.\nSELECT id FROM orders WHERE status = 'pending';\n-- Apply the What is SQL? operation, verify affected rows, then commit.\nCOMMIT;</code></pre><h3>Expected result</h3><p>The schema or operation satisfies the stated rule, rejects invalid data, and can be verified with a repeatable query.</p><h3>Production check</h3><ul><li>Test with empty, duplicate, null, and boundary values.</li><li>Use a transaction for related writes.</li><li>Inspect the execution plan before adding an index.</li><li>Use parameterized queries for application input.</li></ul><h3>Continue with the PicoStore database</h3><p>This lesson reuses <strong>picostore</strong>. Relevant tables: <code>customers, products, orders, order_items</code>. Keep the starter rows from the Introduction lesson so results remain comparable.</p><h3>Another practical example</h3><pre><code>SELECT o.order_id, c.name AS customer, o.status, o.total\nFROM orders o\nJOIN customers c ON c.customer_id = o.customer_id\nWHERE o.total &gt;= 1000\nORDER BY o.ordered_at DESC;</code></pre><h3>Check the result</h3><p>Run the verification query, compare the returned rows with the starter data, and explain why every included or excluded row is correct.</p><section data-sql-reference-catalog=\"true\"><h2>SQL reference catalog: What is SQL?</h2><p>This catalog covers the practical public SQL surface. Check the exact server-version documentation before using a vendor-specific item.</p><h3>SQL command families</h3><ul><li><code>DQL</code> — SELECT queries data</li><li><code>DDL</code> — CREATE, ALTER, DROP, TRUNCATE, RENAME define structures</li><li><code>DML</code> — INSERT, UPDATE, DELETE, MERGE change rows</li><li><code>DCL</code> — GRANT and REVOKE control access</li><li><code>TCL</code> — BEGIN, COMMIT, ROLLBACK, SAVEPOINT control transactions</li></ul><h3>Core query clauses in logical order</h3><ul><li><code>WITH</code> — defines common table expressions</li><li><code>SELECT</code> — chooses expressions and columns</li><li><code>FROM</code> — chooses source tables</li><li><code>JOIN ... ON</code> — combines related sources</li><li><code>WHERE</code> — filters rows before grouping</li><li><code>GROUP BY</code> — forms groups</li><li><code>HAVING</code> — filters groups</li><li><code>WINDOW</code> — names reusable window definitions</li><li><code>ORDER BY</code> — sorts the result</li><li><code>LIMIT / OFFSET or FETCH</code> — restricts returned rows</li></ul></section><section data-nonversioned-curriculum=\"1\"><h3>Easy example</h3><p>Start with a small customer table and retrieve active customers in a predictable order.</p><pre><code>SELECT customer_id, name, email\nFROM customers\nWHERE status = 'active'\nORDER BY name;</code></pre><h3>How to verify the easy example</h3><ul><li>Run it with representative input.</li><li>Confirm the expected output.</li><li>Try one missing, invalid, or boundary value.</li></ul><h3>Advanced example</h3><p>Use a CTE and a window function to rank customer revenue while keeping the query readable and testable.</p><pre><code>WITH customer_revenue AS (\n  SELECT customer_id, SUM(total_amount) AS revenue\n  FROM orders\n  WHERE order_status = 'completed'\n  GROUP BY customer_id\n)\nSELECT customer_id, revenue,\n       DENSE_RANK() OVER (ORDER BY revenue DESC) AS revenue_rank\nFROM customer_revenue\nORDER BY revenue_rank, customer_id;</code></pre><h3>Advanced review</h3><ul><li>Explain the tradeoffs and assumptions.</li><li>Test failure, scale, security, and recovery behavior.</li><li>Capture evidence from tests, execution plans, logs, or review output.</li></ul><h3>Additional practical guidance</h3><div><h3>What is SQL?: MySQL and PostgreSQL</h3><p>Use standard SQL first, then document any MySQL or PostgreSQL-specific syntax. Verify the statement with small sample data, an edge case, and the expected result before using it in production.</p><h3>Required verification</h3><ul><li>Run the simple case.</li><li>Test a NULL, duplicate, empty, or boundary case where relevant.</li><li>Confirm the affected rows or query result.</li><li>Use EXPLAIN for performance-sensitive queries.</li></ul></div></section>","detailId":"lesson-what-is-sql-660db64a","versions":[],"isActive":true,"detailIsActive":true,"lessonVersions":[],"selectedVersion":20,"content":"","updatedAt":"2026-08-01T09:43:04.474Z"}]}}