Structure d’une table
id_citation
,texte
&id_film
id_citation
: int,texte
: text &id_film
: intnom
: text,prenom
: text &age
: int
Contenu d’une table
-
SELECT texte FROM citations;
-
SELECT id_citation,texte FROM citations
-
+---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | id_film | int(11) | NO | PRI | NULL | | | titre | varchar(100) | YES | | NULL | | | annee | int(11) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+
-
SELECT * FROM films
-
SELECT * FROM citations WHERE id_citation < 6;
-
SELECT * FROM citations WHERE texte LIKE '%je%';
-
SELECT * FROM citations WHERE texte LIKE '%je%' AND texte LIKE '%!';
-
SELECT * FROM citations WHERE texte LIKE texte LIKE '%est%' AND id_citation < 11;
-
Ça marche 😱😱😱
-
UPDATE citations SET texte = 'C'est dans ses rêves que l'homme trouve la liberté, cela fut, est, et restera la vérité.' WHERE id_citation = 5;
-
INSERT INTO citations VALUES (16, 'Je suis ton père', 0);
-
INSERT INTO citations VALUES (16, 'Je suis ton père', 0);
-
DELETE FROM citations WHERE id_citation = 16,
Clé primaire, clé étrangère
- La clef primaire de la table
films
s’appelleid_film
. - Il exite plusieurs entrées
id_film
de même valeur sur la tablecitation
, hors cela est impossible pour une clef primaire. -
INSERT INTO citations VALUES (12, 'Star Wars V', 1980);
-
UPDATE citations SET id_film = 12 WHERE id_film = 0;
Jointure
-
SELECT texte, titre, annee FROM citations JOIN films ON citations.id_film = films.id_film WHERE films.annee < 2000;
Compléments
-
SELECT titre, annee FROM films ORDER BY titre ASC;
-
SELECT texte, titre FROM citations JOIN films ON citations.id_film = films.id_film ORDER BY films.annee ASC;
Exercies
-
+--------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------+--------------+------+-----+---------+-------+ | rank | int(11) | NO | PRI | NULL | | | artist | varchar(100) | YES | | NULL | | | title | varchar(100) | YES | | NULL | | | year | int(11) | YES | | NULL | | +--------+--------------+------+-----+---------+-------+
-
SELECT * from songs ORDER BY rank ASC;
-
SELECT artist, title from songs WHERE rank = 100;
-
SELECT * from songs WHERE artist = "Aretha Franklin";
-
SELECT * from songs WHERE year >= 2000 ORDER BY year ASC;
-
SELECT count(*) from songs WHERE year <= 2000 AND year >= 1900;
-
SELECT * from songs WHERE title LIKE '%rock%';
-
SELECT * from songs WHERE year = 1971;
-
SELECT count(*) AS nb, year from songs GROUP BY year ORDER BY nb DESC;
-
SELECT count(*) AS nb, artist from songs GROUP BY artist ORDER BY nb DESC;