5 Basic Types of SQL Queries
- DDL – Data Definition Language: Collection of commands which defines the database structure.
- CREATE
- DROP
- ALTER
- TRUNCATE
- DML – Data Manipulation Language: Collection of main commands which manipulates data.
- INSERT
- UPDATE
- DELETE
- DQL – Data Query Language: Collection of commands to query and retrieve data.
- SELECT
- DISTINCT
- AS
- WHERE, AND / OR, LIKE,
- LIMIT
- ORDER BY
- GROUP BY, HAVING
- INNER/OUTER JOIN
- WITH
- SUM(), AVG(), … aggregate functions
- DCL – Data Control Language: Collection of commands used for access control.
- GRANT
- REVOKE
- TCL – Transaction Control Language: Collection of commands used to ensure data consistency.
- COMMIT
- ROLLBACK
- SAVEPOINT
About query execution order

Important points to note related to above query execution order:
- If a “JOIN” is used without the “ON” condition, it will defaults to a Cross JOIN which produces the cartesian product of two tables. This can produce a huge number of rows if the tables are large.
Let’s understand SQL using a few Queries
Query #1
The following single query gives the order details, total amounts, a running total per customer, and average order value all in a structured reference query.

Concepts Used in This Query:
- Common Table Expression (CTE) – WITH ordersummary AS (…)
- A nested SELECT query
- Aggregation – SUM(o.total) OVER (…) AS runningTotal
- Joins – JOIN tb1 ON condition
- Where filtering – WHERE condition
- SELECT query.
- A nested SELECT query used with aggregation
- Nested query is used in filtering
- Grouping – GROUP BY col1, col2, …
- Having Clause affect for Grouped results – HAVING COUNT (os.orderId) > 0
- Sorting – ORDER BY os.runningTotal DESC
- Limiting the final results – LIMIT 1
Leave a Reply