Bonjour a tous,
J'ai trois tables :
tmp2(NumSerie)
Stock(NumSerie, RefVehicule)
Prep_Comm(RefVehicule)
Par exemple :
tmp2 :
123
124
125
128
Stock :
123 BLA
124 BLA
125 BLU
126 YEL
127 RED
Prep_Comm:
BLA
RED
PIN
Je souhaite ecrire une requete qui me retournera comme resultat :
NumSerie Statut
123 En stock, au moins une refvehicule existe dans prep_comm
124 En stock, au moins une refvehicule existe dans prep_comm
125 En stock, aucune refvehicule existante dans prep_comm
128 Pas en stock
Pour l'instant, j'ai ça :
Ma question est juste de savoir si cette requete correspond bien au resultat attendu, si au niveau des cas possibles tout est pris en compte ? Si d'autres solutions existent, plus optimales, faites moi signe.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 SELECT distinct "En stock, au moins une refvehicule existe dans prep_comm" AS lib, tmp2.NumSerie FROM Stock, tmp2 WHERE Stock.NumSerie=tmp2.NumSerie and Stock.RefVehicule IN (SELECT Preparation_Commande.RefVehicule FROM Preparation_Commande) UNION ALL SELECT distinct "En stock, aucune refvehicule existante dans prep_comm" AS lib, tmp2.NumSerie FROM Stock, tmp2 WHERE Stock.NumSerie=tmp2.NumSerie and Stock.RefVehicule NOT IN (SELECT Preparation_Commande.RefVehicule FROM Preparation_Commande) UNION ALL SELECT distinct "Pas en stock" AS lib, tmp2.NumSerie FROM tmp2 WHERE tmp2.NumSerie NOT IN (SELECT Stock.NumSerie FROM Stock)
Merci beaucoup
Partager