Informatique s3

FSJEST13
Chapitre 5 :
Le langage SQL
Introduction : présentation du SQL
I. La projection
II. La restriction
III. Le tri
IV. La jointure
Introduction : présentation du SQL
15
SQL
Structured Query Language
Le langage structuré de requêtes permet :
 De manipuler les bases de données quel que soit le
logiciel utilisé
 De réaliser des requêtes
Les instructions SQL
 SELECT
 FROM
 WHERE
 ORDER BY
Construction d'une requête SQL
Le raisonnement est le suivant :
Quoi ? quelles informations obtenir ?
Où ? dans quelles tables ?
Comment ? (jointures, restrictions…)
I. La projection
Thème - Requête n° 1 :
Afficher la liste des adhérents (Nom, Prénom, Code
postal, Ville)
Quoi ? Nom_adh, Prénom_adh, Cp_adh, Ville_adhSELECT
Où ? ADHERENTFROM
SELECT
FROM
I. La projection
Critère de projection. C’est un ordre qui décrit les
champs que l’on désire extraire et afficher.
C’est une clause qui précise les tables
nécessaires à la requête.
La présence de FROM est obligatoire et suit
SELECT.
II. La restriction
Thème - Requête n° 2 :
Afficher la liste des adhérents (numéro,
nom, prénom, index) dont l’index est
inférieur à 20
Quoi ? Num_adh, Nom_adh, Prénom_adh, Index_adhSELECT
Où ? ADHERENTFROM
Comment ? Index_adh < 20WHERE
II. La restriction
WHERE C’est une clause qui décrit les critères de
restriction.
S’il n’y a pas de restriction, la ligne WHERE
n’existe pas.
III. Le tri
Thème - Requête n° 3 :
Afficher la liste des adhérents (nom,
prénom, code postal, ville) dans
l’ordre alphabétique du nom.
Quoi ? Nom_adh, Prénom_adh, Cp_adh, Ville_adhSELECT
Où ? ADHERENTFROM
ORDER BY Nom_adh
Tri sur le nom
III. Le tri
ORDER BY C’est une clause qui décrit les critères de TRI.
L’ordre croissant est traduit par ASC.
L’ordre décroissant est traduit par DESC.
En l’absence de paramètre, c’est ASC qui est
retenu par défaut.
IV. La jointure
Thème - Requête n° 4 :
Afficher la liste des adhérents
seniors (nom, prénom, intitulé
de la formule) dans l’ordre
croissant du nom et du prénom.
Quoi ?
Où ?
Comment ?
Nom_adh, Prénom_adh, intitulé_for
ADHERENT, FORMULE
SELECT
FROM
WHERE
Code_cat=6 AND
ADHERENT.Code_for=FORMULE.Code_for
ORDER BY Nom_adh, Prénom_adh
IV. La jointure
WHERE C’est une clause qui décrit aussi le critère de
jointure.
Lorsqu’il y a jointure entre deux tables, les
tables sont mentionnées en ligne FROM et le
critère de jointure fait partie des éléments de la
ligne WHERE, lié par AND aux autres critères
de restriction.
Le préfixage est nécessaire pour préciser de
quelle table sont issus les champs concernés
par la jointure.
1 sur 11

Recommandé

Sql par
SqlSql
Sqlkrymo
1.7K vues30 diapositives
SGBDR - MySQL par
SGBDR - MySQLSGBDR - MySQL
SGBDR - MySQLMusatge
4.9K vues121 diapositives
Le langage sql par
Le langage sqlLe langage sql
Le langage sqlAbderrahim Aitali
1.9K vues43 diapositives
SQL partie III par
SQL partie IIISQL partie III
SQL partie IIIyassine kchiri
1.1K vues8 diapositives
Alphorm.com Formation le langage SQL par
Alphorm.com  Formation le langage SQLAlphorm.com  Formation le langage SQL
Alphorm.com Formation le langage SQLAlphorm
164.1K vues205 diapositives
Le langage SQL par
Le langage SQLLe langage SQL
Le langage SQLBruno Delb
1.8K vues26 diapositives

Contenu connexe

En vedette

ChatGPT and the Future of Work - Clark Boyd par
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
20.3K vues69 diapositives
Getting into the tech field. what next par
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
5K vues22 diapositives
Google's Just Not That Into You: Understanding Core Updates & Search Intent par
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
5.8K vues99 diapositives
How to have difficult conversations par
How to have difficult conversations How to have difficult conversations
How to have difficult conversations Rajiv Jayarajah, MAppComm, ACC
4.3K vues19 diapositives
Introduction to Data Science par
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceChristy Abraham Joy
82.1K vues51 diapositives
Time Management & Productivity - Best Practices par
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
169.6K vues42 diapositives

En vedette(20)

ChatGPT and the Future of Work - Clark Boyd par Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd20.3K vues
Getting into the tech field. what next par Tessa Mero
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero5K vues
Google's Just Not That Into You: Understanding Core Updates & Search Intent par Lily Ray
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray5.8K vues
Time Management & Productivity - Best Practices par Vit Horky
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky169.6K vues
The six step guide to practical project management par MindGenius
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius36.6K vues
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... par RachelPearson36
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson3612.6K vues
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... par Applitools
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools55.4K vues
12 Ways to Increase Your Influence at Work par GetSmarter
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter401.6K vues
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... par DevGAMM Conference
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference3.6K vues
Barbie - Brand Strategy Presentation par Erica Santiago
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K vues
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well par Saba Software
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software25.2K vues
Introduction to C Programming Language par Simplilearn
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn8.4K vues
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr... par Palo Alto Software
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
Palo Alto Software88.3K vues
9 Tips for a Work-free Vacation par Weekdone.com
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K vues
How to Map Your Future par SlideShop.com
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K vues

Informatique s3

  • 1. Chapitre 5 : Le langage SQL Introduction : présentation du SQL I. La projection II. La restriction III. Le tri IV. La jointure
  • 2. Introduction : présentation du SQL 15 SQL Structured Query Language Le langage structuré de requêtes permet :  De manipuler les bases de données quel que soit le logiciel utilisé  De réaliser des requêtes Les instructions SQL  SELECT  FROM  WHERE  ORDER BY
  • 3. Construction d'une requête SQL Le raisonnement est le suivant : Quoi ? quelles informations obtenir ? Où ? dans quelles tables ? Comment ? (jointures, restrictions…)
  • 4. I. La projection Thème - Requête n° 1 : Afficher la liste des adhérents (Nom, Prénom, Code postal, Ville) Quoi ? Nom_adh, Prénom_adh, Cp_adh, Ville_adhSELECT Où ? ADHERENTFROM
  • 5. SELECT FROM I. La projection Critère de projection. C’est un ordre qui décrit les champs que l’on désire extraire et afficher. C’est une clause qui précise les tables nécessaires à la requête. La présence de FROM est obligatoire et suit SELECT.
  • 6. II. La restriction Thème - Requête n° 2 : Afficher la liste des adhérents (numéro, nom, prénom, index) dont l’index est inférieur à 20 Quoi ? Num_adh, Nom_adh, Prénom_adh, Index_adhSELECT Où ? ADHERENTFROM Comment ? Index_adh < 20WHERE
  • 7. II. La restriction WHERE C’est une clause qui décrit les critères de restriction. S’il n’y a pas de restriction, la ligne WHERE n’existe pas.
  • 8. III. Le tri Thème - Requête n° 3 : Afficher la liste des adhérents (nom, prénom, code postal, ville) dans l’ordre alphabétique du nom. Quoi ? Nom_adh, Prénom_adh, Cp_adh, Ville_adhSELECT Où ? ADHERENTFROM ORDER BY Nom_adh Tri sur le nom
  • 9. III. Le tri ORDER BY C’est une clause qui décrit les critères de TRI. L’ordre croissant est traduit par ASC. L’ordre décroissant est traduit par DESC. En l’absence de paramètre, c’est ASC qui est retenu par défaut.
  • 10. IV. La jointure Thème - Requête n° 4 : Afficher la liste des adhérents seniors (nom, prénom, intitulé de la formule) dans l’ordre croissant du nom et du prénom. Quoi ? Où ? Comment ? Nom_adh, Prénom_adh, intitulé_for ADHERENT, FORMULE SELECT FROM WHERE Code_cat=6 AND ADHERENT.Code_for=FORMULE.Code_for ORDER BY Nom_adh, Prénom_adh
  • 11. IV. La jointure WHERE C’est une clause qui décrit aussi le critère de jointure. Lorsqu’il y a jointure entre deux tables, les tables sont mentionnées en ligne FROM et le critère de jointure fait partie des éléments de la ligne WHERE, lié par AND aux autres critères de restriction. Le préfixage est nécessaire pour préciser de quelle table sont issus les champs concernés par la jointure.