What is SQL?
The standard language for defining tables, searching, inserting, updating and deleting data, and controlling privileges in relational databases. It is standardized by ISO/IEC. Its statements include SELECT, INSERT, UPDATE, DELETE, CREATE TABLE and GRANT.
Japanese name: SQL
SQL appears in 15 practice questions across 3 topics, including Database Basics, Information Security Basics, IC design flow and EDA.
Field: Database Basics
Kinds of SQL statements
SQL statements fall into three broad groups by role. The data definition language (DDL), such as CREATE, ALTER and DROP, defines structures like tables, views and indexes. The data manipulation language (DML), such as SELECT, INSERT, UPDATE and DELETE, handles the data in tables. The data control language (DCL), such as GRANT and REVOKE, controls privileges. COMMIT, which makes a transaction permanent, and ROLLBACK, which cancels it, are sometimes counted as DCL and sometimes treated separately as transaction control statements.
Clauses of the SELECT statement and their processing order
A SELECT statement is written by listing clauses, as in SELECT columns FROM table WHERE condition GROUP BY columns HAVING condition ORDER BY columns. Unlike the written order, it is easier to understand the processing as FROM (choose and join tables), WHERE (select rows), GROUP BY (form groups), HAVING (select groups), SELECT (take columns and compute aggregate functions) and ORDER BY (sort). This is why aggregate functions cannot be written in WHERE and conditions on groups go in HAVING.
FAQ
What is the difference between the WHERE and HAVING clauses in SQL?
The WHERE clause is a condition on individual rows before grouping, and aggregate functions cannot be written in it. The HAVING clause is a condition on the groups formed by GROUP BY, and it can use aggregate functions, as in HAVING SUM(amount) >= 1000.
How do you find rows containing NULL in SQL?
Write WHERE column IS NULL. WHERE column = NULL selects no rows, because a comparison with NULL is never true. Rows that are not NULL are selected with IS NOT NULL.