SQL
Published:
SQL is a relational database NoSQL is non-relational database
SQL (Structral Query Language)
Basic Concept
Primary Key: The primary key cannot be the same and try not to change
Foriegn Key: The Foriegn key can connect many tables
The SQL Language
Basic Search
Search for every row in the table:
SELECT * FROM <The name of the table>
SELECT 100+200
Calculate 100+200=300
Conditional Search
SELECT * From <The name of the table> WHERE <Condition 1> AND/OR <Condition 2>
Projection Search
Search for some columns in the table and can substitute their name
SELECT id, score points, name FROM <The name of the table> WHERE <Condition>
Sorting
SELECT id, score, name
FROM <The name of the table>
WHERE <Condition>
ORDER BY <the key to be sorted>
Devide the page
SELECT id, score, name
FROM <The name of the table>
WHERE <Condition>
ORDER BY <the key to be sorted> DESC // in descending order
LIMIT 3 OFFSET 0 //Devide into pages with 3 record in each page, offset = 0 + n * 3
Count the Total Number of the record
SELECT COUNT(*) FROM <The name of the table>
Query From more tables
SELECT * FROM <The name of table 1> <The name of table 2>
JOIN
SELECT s.id, s.name, s.class_id, c.name class_name, s.gender, s.score
FROM students s
INNER JOIN classes c
ON s.class_id = c.id;
