From 6c120acab39a9258c0e66c732ed53111428ec650 Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Thu, 2 Oct 2025 11:45:01 +0200 Subject: [PATCH] =?UTF-8?q?Refactor=20les=20requ=C3=AAtes=20SQL=20pour=20u?= =?UTF-8?q?tiliser=20des=20jointures=20explicites=20et=20ajouter=20une=20a?= =?UTF-8?q?lternative=20avec=20MIN=20pour=20la=20comparaison=20de=20dates.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- M2/SQL/scripts/TP2.sql | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/M2/SQL/scripts/TP2.sql b/M2/SQL/scripts/TP2.sql index fc7a8f0..2428d83 100644 --- a/M2/SQL/scripts/TP2.sql +++ b/M2/SQL/scripts/TP2.sql @@ -64,16 +64,14 @@ SELECT Enom, Salaire FROM Employe WHERE Salaire < 4000; -- Q2.6 SELECT 'Q2.6'; -SELECT Enom, Prof FROM Employe e -JOIN Departement d ON e.Dep = d.Dno -WHERE d.Ville = 'Lyon'; +SELECT e.Enom, e.Prof FROM Employe e, Departement d +WHERE e.Dep = d.Dno AND d.Ville = 'Lyon'; -- Q2.7 SELECT 'Q2.7'; -SELECT Enom, Prof FROM Employe e -JOIN Departement d ON d.Directeur = e.Eno -WHERE d.Dnom = 'Production'; +SELECT Enom, Prof FROM Employe e, Departement d +WHERE d.Directeur = e.Eno AND d.Dnom = 'Production'; -- Q2.8 SELECT 'Q2.8'; @@ -175,6 +173,13 @@ WHERE e.Date_Emb < ALL ( WHERE e2.Dep = 2 ); +-- As an alternative to ALL, we can use a subquery with MIN. ALL is not supported in SQLite. +SELECT e.Enom, e.Date_Emb FROM Employe e +WHERE e.Date_Emb < ( + SELECT MIN(e2.Date_Emb) FROM Employe e2 + WHERE e2.Dep = 2 +); + -- Q2.21 SELECT 'Q2.21';