Voici la syntaxe (sans les détails):
SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [DISTINCT | DISTINCTROW | ALL]
select_expression,...
[INTO OUTFILE ’file_name’ export_options]
[FROM table_references
[WHERE where_definition]
[GROUP BY col_name,...]
[HAVING where_definition]
[ORDER BY {unsigned_integer | col_name} [ASC | DESC] ,...]
[LIMIT [offset,] rows]
[PROCEDURE procedure_name] ]
Nous allons ici travailler surtout avec la forme suivante
SELECT
select_expression
1
FROM
table_references
WHERE
where_definition
2
ORDER BY
col_name
1
select_expression:
une liste de colonnes à chercher
2
where_definition:
voir 3.2 “Sélection conditionnelle (SELECT .... WHERE)” [10]
SELECT champs1,champs2,... FROM table OU
SELECT
id,login,fullname,love,sports
FROM
demo1
+----+-----------+------------------+------+--------+
| id | login | fullname | love | sports |
+----+-----------+------------------+------+--------+
| 1 | test | Tester Test | 3 | 3 |
| 34 | colin2 | Patrick Jermann2 | 1 | 4 |
....
+----+-----------+----------------------------------+------------------+------------------------+------+--.....| id | login | password | fullname | url | food | w.....+----+-----------+----------------------------------+------------------+------------------------+------+---.....| 1 | test | 098f6bcd4621d373cade4e832627b4f6 | Tester Test | http://tecfa.unige.ch | 3 | ...| 34 | colin2 | b9hhhfa9347all893u483 | Patrick Jermann2 | http://tecfa.unige.ch/ | 1 | ...
SELECT .... FROM table WHERE condition
SELECT id,login,fullname,love,sports FROM demo1 WHERE love>4+----+----------+------------------+------+--------+| id | login | fullname | love | sports |+----+----------+------------------+------+--------+| 3 | colin | Patrick Jermann | 6 | 4 || 4 | schneide | Daniel Schneider | 6 | 6 |+----+----------+----------------+------+--------+
SELECT * from demo1 WHERE food BETWEEN 3 AND 5
SELECT fullname from demo1 WHERE food BETWEEN 3 AND 5 AND love > 2
SELECT id,login,fullname,love,sports FROM demo1
WHERE fullname LIKE ’%Patrick%’;
+----+----------+------------------+------+--------+
| id | login | fullname | love | sports |
+----+----------+------------------+------+--------+
| 3 | colin | Patrick Jermann | 6 | 4 |
| 93 | michelon | Michelon Patrick | 6 | 6 |
+----+----------+------------------+------+--------+
SELECT * from demo1 ORDER by id
SELECT * from demo1 ORDER by id DESC
SELECT demo1.fullname FROM demo1, test WHERE demo1.login = test.login
+-------------+
| fullname |
+-------------+
| Tester Test |