Difference between revisions of "SELECT bases"
From SQLZOO
(Created page with "A SELECT statement gets data from a table. Each table contains rows and columns - you can SELECT some columns and ignore others *The column names on the select line control wh...") |
|||
| (4 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | [[Main_Page/fr|Retour à la page principale]] | |
| − | * | + | |
| − | * | + | L'instruction SELECT permet de lire les données d'une table. Chaque table contient des lignes et des colonnes - vous pouvez SELECTionner certaines colonnes et en ignorer d'autres |
| + | *Le nom des colonnes sur la ligne sélection définie quelles colonnes vous obtiendrez | ||
| + | *L'instruction FROM définie à quelle table vous accédez | ||
<div class=params>schema:scott</div> | <div class=params>schema:scott</div> | ||
| − | + | La table <code>jeux</code> contient l'année et la ville qui a organisé les Jeux Olympiques. | |
<table border='1'> | <table border='1'> | ||
| − | <caption> | + | <caption>jeux</caption> |
| − | <tr> <th> | + | <tr> <th>annee</th> <th>ville</th> </tr> |
<tr> <td align='right'>2000</td> <td>Sydney</td> </tr> | <tr> <td align='right'>2000</td> <td>Sydney</td> </tr> | ||
<tr> <td align='right'>2004</td> <td>Athens</td> </tr> | <tr> <td align='right'>2004</td> <td>Athens</td> </tr> | ||
| Line 13: | Line 15: | ||
</table> | </table> | ||
<div class=qu> | <div class=qu> | ||
| − | + | L'instruction SELECT retourne les résultats depuis la <i>table</i>. | |
| − | + | Dans cet exemple, la table est <code>jeux</code> et les colonnes sont | |
| − | <code> | + | <code>annee</code> et <code>ville</code>. |
<div class=tidy> | <div class=tidy> | ||
| − | DROP TABLE | + | DROP TABLE jeux; |
</div> | </div> | ||
<div class=setup> | <div class=setup> | ||
| − | CREATE TABLE | + | CREATE TABLE jeux(annee INT, ville VARCHAR(20)); |
| − | INSERT INTO | + | INSERT INTO jeux(ville,annee) VALUES ('ouroalpha',2000); |
| − | INSERT INTO | + | INSERT INTO jeux(ville,annee) VALUES ('Athens',2004); |
| − | INSERT INTO | + | INSERT INTO jeux(ville,annee) VALUES ('Beijing',2008); |
| − | INSERT INTO | + | INSERT INTO jeux(ville,annee) VALUES ('London',2012); |
</div> | </div> | ||
<div class=def> | <div class=def> | ||
| − | SELECT | + | SELECT annee, ville FROM jeux |
</div> | </div> | ||
</div> | </div> | ||
| − | === | + | ===Voir aussi:=== |
*[http://sqlzoo.net/w/index.php/SELECT_from_BBC_Tutorial SELECT Tutorial] - practice using the SELECT command | *[http://sqlzoo.net/w/index.php/SELECT_from_BBC_Tutorial SELECT Tutorial] - practice using the SELECT command | ||
*[SELECT_.._WHERE |SELECT ... WHERE] - the WHERE clause allows you to get some rows but not others | *[SELECT_.._WHERE |SELECT ... WHERE] - the WHERE clause allows you to get some rows but not others | ||
Latest revision as of 14:36, 20 December 2012
L'instruction SELECT permet de lire les données d'une table. Chaque table contient des lignes et des colonnes - vous pouvez SELECTionner certaines colonnes et en ignorer d'autres
- Le nom des colonnes sur la ligne sélection définie quelles colonnes vous obtiendrez
- L'instruction FROM définie à quelle table vous accédez
schema:scott
La table jeux contient l'année et la ville qui a organisé les Jeux Olympiques.
| annee | ville |
|---|---|
| 2000 | Sydney |
| 2004 | Athens |
| 2008 | Beijing |
| 2012 | London |
L'instruction SELECT retourne les résultats depuis la table.
Dans cet exemple, la table est jeux et les colonnes sont
annee et ville.
DROP TABLE jeux;
CREATE TABLE jeux(annee INT, ville VARCHAR(20)); INSERT INTO jeux(ville,annee) VALUES ('ouroalpha',2000); INSERT INTO jeux(ville,annee) VALUES ('Athens',2004); INSERT INTO jeux(ville,annee) VALUES ('Beijing',2008); INSERT INTO jeux(ville,annee) VALUES ('London',2012);
SELECT annee, ville FROM jeux
[edit] Voir aussi:
- SELECT Tutorial - practice using the SELECT command
- [SELECT_.._WHERE |SELECT ... WHERE] - the WHERE clause allows you to get some rows but not others