SQL beginner course · Chapter 10 of 10
SQL Special Topics and Practice: DUAL, Commands and Exercises explained in simple steps. Examples use practice tables such as students and scores; adapt names to your database.
DUAL table
Oracle uses DUAL to select a calculated expression without a regular table. Other databases may allow SELECT without FROM; this is a dialect difference.
Example
SELECT 2 + 3 AS answer FROM DUAL;Expected result: Oracle returns one row containing 5.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
SQL command families
DDL changes structure, DML changes rows, DQL reads rows, DCL controls permissions, and TCL controls transactions. These labels help organize commands, though teaching materials classify SELECT differently.
Example
CREATE TABLE demo (id INTEGER); INSERT INTO demo (id) VALUES (1); SELECT id FROM demo;Expected result: Structure, data and retrieval are separate steps.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
Practice questions
Use a tiny student database and predict each result before running it. Explain why WHERE comes before grouping and why HAVING comes after grouping.
Example
SELECT grade, COUNT(*) FROM students WHERE active = 1 GROUP BY grade HAVING COUNT(*) > 1;Expected result: Only active students contribute to groups with two or more rows.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
Further practice
Quiz yourself on NULL, joins, duplicates, keys and transaction safety. Read error messages and change one clause at a time.
Example
SELECT DISTINCT grade FROM students ORDER BY grade;Expected result: A sorted list of unique grades appears.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
Mini quiz and answers
Q1: Which clause filters rows before GROUP BY? WHERE. Q2: Which clause filters groups? HAVING. Q3: Does COUNT(column) count NULL? No. Q4: What is the safe way to pass user input? Parameterized queries.
Example
SELECT grade, COUNT(*) AS total FROM students GROUP BY grade HAVING COUNT(*) > 1;Expected result: Each listed grade has at least two students.
Practice: Predict the result, run the query on a practice database, then change one part and explain what changed. For write commands, use disposable data.
Quick review
Explain each concept in your own words. Recreate one example without looking at the code. Compare your result with the expected result above.
Browse the full SQL learning path. This is original teaching material; the syllabus was checked against the w3resource SQL tutorial index.
No comments:
Post a Comment
Please do not enter any spam link in the comment box.