Retrieving Individual Columns . 检索单个列
SELECT Name
FROM country
Retrieving Multiple Columns 检索多个列
SELECT Name, Continent, Population
FROM country
Retrieving All Columns 检索所有列
SELECT *
FROM countrylanguage
Retrieving Distinct Columns 检索不同的列
SELECT DISTINCT CountryCode
FROM countrylanguage
Limiting Results 极限结果
MySQL,PostgreSQL,SQLite
/* first five rows */
SELECT Name
FROM country
LIMIT 5
/* from the 6th to the 10th rows */
SELECT Name
FROM country
LIMIT 5, 5
Ms SQL,Access
SELECT TOP 5 Name
FROM country
DB2
SELECT Name
FROM country
FETCH FIRST 5 ROWS ONLY
Oracle
SELECT Name
FROM country
WHERE ROWNUM <= 5
Interbase,Firebird
/* first five rows */
SELECT Name
FROM country
ROWS 5
/* from the 6th to the 10th rows */
SELECT Name
FROM country
ROWS 6 TO 10
Using Comments 使用注释
# first comment
SELECT Name -- second comment
FROM country
/* third
comment */
Heavy life list 重命名列
SELECT device_id as user_infors_example
FROM user_profile
Select Clause Ordering 选择子句排序
Clause Ordering:
Предложение | Описание | Необходимость |
---|---|---|
SELECT | Columns or expressions to be returned | Yes |
FROM | Table or subquery to retrieve data from | Yes |
WHERE | Row-level filtring | No |
GROUP BY | Group specification | Only if calculating aggregates by group |
HAVING | Group-level filtring | No |
ORDER BY | Output sort order | No |