title: 01-Basic-MySQL
date: 2023-11-17
status: DONE
tags:
- MySQL
- NOTE
- Lec1
author:
- AllenYGY
created: 2023-11-17T15:52
updated: 2024-03-21T21:43
publish: True
Basic-MySQL
The basic query has three clauses: SELECT, FROM, and WHERE.
SELECT: contains one or multiple attributes.
These attributes are displayed in the result.
The symbol “*” means all attributes.
The FROM clause contains one or more tables.
The WHERE clause contains a single predicate.
It is a logical test on every row of the table which returns true or false.
If multiple queries are executed at the same time, a semicolon “;” is used as a delimiter to split two queries.
A query is executed as follows.
The system test the predicate on every tuple from the table in the FROM clause.
If a tuple satisfies the predicate, show the values of the attributes in the SELECT clause in the result.
pred = term
term = exp op exp
“exp” is an arithmetic expression which contains attributes and constants.
For example
rental_rate < 1
pred = NOT pred
pred = pred AND pred
pred = pred OR pred
NOT, AND, OR are logical operators.
For example,
NOT rental_rate < 1
(NOT rental_rate < 1) AND release_year = 2006
SELECT * FROM film WHERE rating="PG-13"
SQL is case insensitive.
However, to make query readable, we write
key words (like SELECT, FROM, etc.) in capital;
attributes and tables in lower cases; and string constant in the original form.
In general, a basic query is in the form
SELECT a1,⋯,an FROM r WHERE P
where