IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage SQL Discussion :

Alternative à Left join


Sujet :

Langage SQL

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2014
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 42
    Points : 35
    Points
    35
    Par défaut Alternative à Left join
    Bonjour,

    Je suis en train de migrer des requetes access en Linq 3.5

    Je suis donc obligé d'enlever les LEFT JOIN de mes requetes car avec le framework 3.5, ce n'est pas possible de le faire

    Mes left join sont dans des sous requetes

    J'ai besoin d'aide pour choisir une alternative au left join dans mes requetes

    Voici le code SQL :

    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
    17
    18
    19
     
    SELECT Tbl_TP.[Identifiant intervention], 
    Tbl_Multi_Intervenants.[Identifiant tâche], 
    Tbl_TP.[Société Intervenant] + '|' + 
    Tbl_TP.[Nom - prénom intervenant] + '|' + 
    Tbl_TP.[GSM Intervenant] + '|' + 
    Tbl_TP.[Mail Intervenant] + '/' AS Intervenants 
    FROM Tbl_TP 
     
    INNER JOIN (Tbl_Multi_Intervenants LEFT JOIN Tbl_Traitement_GAPP ON Tbl_Multi_Intervenants.[Identifiant tâche] = Tbl_Traitement_GAPP.[Identifiant tâche]) 
     
    ON Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
     
    GROUP BY Tbl_TP.[Identifiant intervention], 
    Tbl_Multi_Intervenants.[Identifiant tâche], 
    Tbl_TP.[Société Intervenant] + '|' + 
    Tbl_TP.[Nom - prénom intervenant] + '|' + 
    Tbl_TP.[GSM Intervenant] + '|' + 
    Tbl_TP.[Mail Intervenant] + '/'
    Et voici la requete que j'ai fait :

    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
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    SELECT Tbl_TP.[Identifiant intervention],
    	Tbl_Multi_Intervenants.[Identifiant tâche], 
    	Tbl_TP.[Société Intervenant] + '|' + 
    	Tbl_TP.[GSM Intervenant] + '|' +  
    	Tbl_TP.[Mail Intervenant] + '/' AS Intervenants 
    	FROM Tbl_TP
    	INNER JOIN Tbl_Multi_Intervenants
              ON Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
         GROUP BY Tbl_TP.[Identifiant intervention],
    	Tbl_Multi_Intervenants.[Identifiant tâche], 
    	Tbl_TP.[Société Intervenant] + '|' + 
    	Tbl_TP.[GSM Intervenant] + '|' +  
    	Tbl_TP.[Mail Intervenant] + '/'     
    	UNION
    	(
    	SELECT Tbl_TP.[Identifiant intervention], 
    				Tbl_Multi_Intervenants.[Identifiant tâche], 
    				Tbl_TP.[Société Intervenant] + '|' + 
    				Tbl_TP.[Nom - prénom intervenant] + '|' + 
    				Tbl_TP.[GSM Intervenant] + '|' + 
    				Tbl_TP.[Mail Intervenant] + '/' 
    	FROM Tbl_TP,Tbl_Multi_Intervenants
    	WHERE NOT EXISTS 
    	(
                       SELECT * 
                         FROM Tbl_Multi_Intervenants
                        WHERE Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
     
    	)
    	GROUP BY Tbl_TP.[Identifiant intervention], 
    				Tbl_Multi_Intervenants.[Identifiant tâche], 
    				Tbl_TP.[Société Intervenant] + '|' + 
    				Tbl_TP.[Nom - prénom intervenant] + '|' + 
    				Tbl_TP.[GSM Intervenant] + '|' + 
    				Tbl_TP.[Mail Intervenant] + '/' 
    	)
    Comme les deux requêtes ne renvoient pas le même nombre de lignes, je me doute que j'ai fait une erreur

    Pouvez-vous m'aiguiller ?

    Merci d'avance

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Responsable Données
    Inscrit en
    Janvier 2009
    Messages
    5 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Responsable Données

    Informations forums :
    Inscription : Janvier 2009
    Messages : 5 197
    Points : 12 772
    Points
    12 772
    Par défaut
    Bonjour,
    Je ne vois pas trop à quoi sert la jointure externe dans la requête, car la table Tbl_Traitement_GAPP n'apparait nul par ailleurs.
    On peut aussi se demander à quoi sert le GROUP BY, vu qu'il n'y a aucune fonction d'agrégation dans le SELECT.

    Tatayo.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2014
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 42
    Points : 35
    Points
    35
    Par défaut
    Bonjour Tatayo,

    Merci d'avoir répondu

    Ce n'est pas moi qui ai fait la requete. Je dois juste enlever le left join

    Je ne suis pas trop calé sur les jointures

    Pourrais tu m'ecrire un bout de requête corrigée ?

    Merci encore

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    956
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 956
    Points : 1 199
    Points
    1 199
    Par défaut
    Bonjour,
    Je suis d'accord avec Tatayo, je dirais que ta première requête est équivalente à
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    SELECT distinct Tbl_TP.[Identifiant intervention], 
    Tbl_Multi_Intervenants.[Identifiant tâche], 
    Tbl_TP.[Société Intervenant] + '|' + 
    Tbl_TP.[Nom - prénom intervenant] + '|' + 
    Tbl_TP.[GSM Intervenant] + '|' + 
    Tbl_TP.[Mail Intervenant] + '/' AS Intervenants 
    FROM Tbl_TP 
     
    INNER JOIN (Tbl_Multi_Intervenants 
    ON Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
    J'ai mis un distinct à la place du group by, car la seule raison que j'ai vu au group by est le dédoublonnage.

    Par contre je ne comprends pas la mention de Linq, Les syntaxes de Linq et de SQL sont différentes, ce que j'ai retenu sur Linq, c'est qu'il ne faut pas traduire la requete SQL en linq, car ce n'est pas la même logique.
    Par ailleurs pour moi il est possible de faire des jointures externes, pas simplement mais c'est possible.

    Cordialement
    Soazig

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2014
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 42
    Points : 35
    Points
    35
    Par défaut
    Bonjour Soazig,

    Merci de ton aide

    J'utilise un outil qui s'appelle Linqer. Il convertit toutes les requetes en SQL en Linq. Le soucis c'est qu'il ne comprend pas les sous requetes car c'est une version .Net 3.5.

    Je pourrai les faire en Linq sans soucis, mais comme je ne peux pas faire tout ce que je veux, je m'adresse à des pros du SQL.

    Pourrais tu m'aider sur celle ci egalement ? ( j'ai attiré ton attention donc j'en profite )

    Comment je peux simplifier cette requête ?

    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
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    SELECT Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], 
                   Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], 
                   Tbl_TP.[Description de l'intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, 
                   Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, 
                   Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, 
                   Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?], Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, 
                   Tbl_TP.[Caractéristiques de l'intervention], Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP.[Chef de projet SFR], Tbl_TP.[Date création intervention (hs)], 
                   Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance 
                   FROM Tbl_Multi_Intervenants 
     
                  INNER JOIN 
                  (
                  Tbl_CONTRATS 
                       INNER JOIN 
                       (Tbl_TP LEFT JOIN Tbl_Traitement_GAPP ON Tbl_TP.[Identifiant tâche] = Tbl_Traitement_GAPP.[Identifiant tâche]) 				
     
                         ON Tbl_CONTRATS.Emplacement = Tbl_TP.[N° Site]) 
    			         ON Tbl_Multi_Intervenants.[Identifiant tâche] = Tbl_TP.[Identifiant tâche]
     
                   WHERE (((Tbl_Traitement_GAPP.[Identifiant tâche]) Is Null))
                   GROUP BY Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], Tbl_TP.[Description de l'intervention], 
                   Tbl_TP.[Identifiant tâche], Tbl_TP.Description, Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, 
                   Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, Tbl_TP.[Validé ?], 
                   Tbl_TP.[Accompagnement ?], Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, 
                   Tbl_TP.[Caractéristiques de l'intervention], Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP.[Chef de projet SFR], 
                   Tbl_TP.[Date création intervention (hs)], Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance;

  6. #6
    Membre éprouvé
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    956
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 956
    Points : 1 199
    Points
    1 199
    Par défaut
    Coucou,
    La prochaine requête tu l'as fait tout seul, sinon tu n'apprendras pas
    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
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    SELECT DIstinct
    		Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], 
    		Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], 
    		Tbl_TP.[Description de l'intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, 
    		Tbl_TP.[Etat administratif intervention], 
    		Tbl_TP.[Date début prévu tâche], 
    		Tbl_TP.[Date fin prévu tâche], 
    		Tbl_TP.Detrompeur, 
    		Tbl_TP.[Entité demandeur], 
    		Tbl_TP.[Infos Demandeur], 
    		Tbl_TP.[Indicateur accompagnement],
    		Tbl_TP.[Code Journalier], Tbl_TP.Coupure, 
    		Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?],
    		Tbl_TP.[Observation ?], Tbl_TP.Accès,
    		Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, 
    		Tbl_TP.[Caractéristiques de l'intervention],
    		Tbl_CONTRATS.[Sensibilité du site],
    		Tbl_CONTRATS.[Approbation automatique AS],
    		Tbl_TP.[Chef de projet SFR], 
    		Tbl_TP.[Date création intervention (hs)], 
    		Tbl_TP.[Identifiant demande],
    		Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance 
                   FROM Tbl_Multi_Intervenants 
                  INNER JOIN Tbl_TP  				 
    	         ON Tbl_Multi_Intervenants.[Identifiant tâche] = Tbl_TP.[Identifiant tâche] 
                  INNER JOIN               
                  Tbl_CONTRATS 
                         ON Tbl_CONTRATS.Emplacement = Tbl_TP.[N° Site]
     
    	      where Not exists (select null from Tbl_Traitement_GAPP where Tbl_TP.[Identifiant tâche] = Tbl_Traitement_GAPP.[Identifiant tâche] )
    Je ne suis pas sure que linq apprécie des noms avec des espaces, ni avec des apostrophes.
    Bonne journée
    Soazig

  7. #7
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2014
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 42
    Points : 35
    Points
    35
    Par défaut
    Soazig,

    Merci de ta réponse.

    Tu as raison, Linq n'apprécie pas les guillemets, j'ai dû ruser pour faire passer ma requête.

    J'ai une autre requete si ça interesse quelqu'un ?

    Je dois rendre tout ça vendredi 30/12, pouvez-vous m'aider ?

    Voici la requete à simmplifier :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    SELECT Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], Tbl_TP.[Description de l'intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?], Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, Tbl_TP.[Caractéristiques de l'intervention], Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP![Société Intervenant] & "|" & Tbl_TP![Nom - prénom intervenant] & "|" & Tbl_TP![GSM Intervenant] & "|" & Tbl_TP![Mail Intervenant] & "/" AS Intervenants, Tbl_TP.[Chef de projet SFR], Tbl_TP.[Date création intervention (hs)], Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance
     
    				FROM ( Tbl_CONTRATS INNER JOIN (Tbl_TP LEFT JOIN Tbl_Traitement_GAPP ON Tbl_TP.[Identifiant tâche] = Tbl_Traitement_GAPP.[Identifiant tâche]) 
     
    				ON Tbl_CONTRATS.Emplacement = Tbl_TP.[N° Site]) 
     
    				LEFT JOIN Tbl_Multi_Intervenants 
     
    				ON Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
     
    				WHERE (((Tbl_Traitement_GAPP.[Identifiant tâche]) Is Null) AND ((Tbl_Multi_Intervenants.[Identifiant tâche]) Is Null))
    				GROUP BY Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], Tbl_TP.[Description de l'intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?], Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, Tbl_TP.[Caractéristiques de l'intervention], Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP![Société Intervenant] & "|" & Tbl_TP![Nom - prénom intervenant] & "|" & Tbl_TP![GSM Intervenant] & "|" & Tbl_TP![Mail Intervenant] & "/", Tbl_TP.[Chef de projet SFR], Tbl_TP.[Date création intervention (hs)], Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance;
    Merci d'avance de votre aide

    ps : Ce sera la dernière

  8. #8
    Expert éminent sénior
    Homme Profil pro
    Responsable Données
    Inscrit en
    Janvier 2009
    Messages
    5 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Responsable Données

    Informations forums :
    Inscription : Janvier 2009
    Messages : 5 197
    Points : 12 772
    Points
    12 772
    Par défaut
    Si tu regardes bien comment ont été modifiés tes précédentes requêtes, tu devrais rapidement trouver tout seul comment modifier celle-ci.

    Tatayo.

  9. #9
    Membre éprouvé
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    956
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 956
    Points : 1 199
    Points
    1 199
    Par défaut
    Bonjour,
    Non, je ne vais pas continuer à faire ton boulot à ta place. Mais je vais t'aider à le faire.
    Si tu regardes ta dernière requête, tu te rendras compte que
    1. les left outer join ne servent que à tester une non existence donc avec un not exist tu t'en sors
      Tu le vois là
      WHERE (((Tbl_Traitement_GAPP.[Identifiant tâche]) Is Null) AND ((Tbl_Multi_Intervenants.[Identifiant tâche]) Is Null)).
    2. que le group by ne sert toujours à rien sauf peut être à dédoublonner


    Bon certes ta requête initiale est ignoble à cause de la sale manie d'access de rajouter des paramètres, mais sinon elle est simple.

    Bon courage
    Soazig

  10. #10
    Nouveau membre du Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2014
    Messages
    42
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2014
    Messages : 42
    Points : 35
    Points
    35
    Par défaut
    Bonjour Soazig ( ainsi qu'à tout le monde )

    Bonne année 2017, plein de bonheur et de merveilleuses requêtes SQL optimisées.

    J'ai travaillé sur la simplification d'une requête ACCESS et voilà ce que ça donne :

    Requete Access :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    	SELECT Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], Tbl_TP.[Description de l'intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?], Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, Tbl_TP.[Caractéristiques de l'intervention], Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP![Société Intervenant] & "|" & Tbl_TP![Nom - prénom intervenant] & "|" & Tbl_TP![GSM Intervenant] & "|" & Tbl_TP![Mail Intervenant] & "/" AS Intervenants, Tbl_TP.[Chef de projet SFR], Tbl_TP.[Date création intervention (hs)], Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance
     
    				FROM ( Tbl_CONTRATS INNER JOIN (Tbl_TP LEFT JOIN Tbl_Traitement_GAPP ON Tbl_TP.[Identifiant tâche] = Tbl_Traitement_GAPP.[Identifiant tâche]) 
     
    				ON Tbl_CONTRATS.Emplacement = Tbl_TP.[N° Site]) 
     
    				LEFT JOIN Tbl_Multi_Intervenants 
     
    				ON Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
     
    				WHERE (((Tbl_Traitement_GAPP.[Identifiant tâche]) Is Null) AND ((Tbl_Multi_Intervenants.[Identifiant tâche]) Is Null))
    				GROUP BY Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], Tbl_TP.[Description de l'intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?], Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, Tbl_TP.[Caractéristiques de l'intervention], Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP![Société Intervenant] & "|" & Tbl_TP![Nom - prénom intervenant] & "|" & Tbl_TP![GSM Intervenant] & "|" & Tbl_TP![Mail Intervenant] & "/", Tbl_TP.[Chef de projet SFR], Tbl_TP.[Date création intervention (hs)], Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance;

    Requete simplifiée :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    SELECT DISTINCT Tbl_TP.Société, Tbl_TP.Région, Tbl_TP.[N° Site], Tbl_TP.[Nom Site], Tbl_TP.[Identifiant intervention], Tbl_TP.[Gamme intervention], Tbl_TP.[Identifiant tâche], Tbl_TP.Description, Tbl_TP.[Etat administratif intervention], Tbl_TP.[Date début prévu tâche], 
    Tbl_TP.[Date fin prévu tâche], Tbl_TP.Detrompeur, Tbl_TP.[Entité demandeur], Tbl_TP.[Infos Demandeur], 
    Tbl_TP.[Indicateur accompagnement], Tbl_TP.[Code Journalier], Tbl_TP.Coupure, Tbl_TP.[Validé ?], Tbl_TP.[Accompagnement ?], 
    Tbl_TP.[Observation ?], Tbl_TP.Accès, Tbl_TP.[Contrainte de sécurité], Tbl_TP.V_Couleur, Tbl_CONTRATS.[Sensibilité du site], Tbl_CONTRATS.[Approbation automatique AS], Tbl_TP.[Chef de projet SFR], Tbl_TP.[Identifiant demande], Tbl_TP.PlanPrevention, Tbl_CONTRATS.Appartenance
    FROM 
    Tbl_CONTRATS 
    INNER JOIN Tbl_TP ON Tbl_CONTRATS.Emplacement = Tbl_TP.[N° Site]
    LEFT JOIN Tbl_Traitement_GAPP 
    ON Tbl_TP.[Identifiant tâche] = Tbl_Traitement_GAPP.[Identifiant tâche]
    LEFT JOIN Tbl_Multi_Intervenants 
    ON Tbl_TP.[Identifiant tâche] = Tbl_Multi_Intervenants.[Identifiant tâche]
    WHERE (((Tbl_Traitement_GAPP.[Identifiant tâche]) Is Null) AND ((Tbl_Multi_Intervenants.[Identifiant tâche]) Is Null))
    Sans la clause where, les deux requetes me renvoient 181 lignes.

    Quand je remet la clause wherre, les deux renvoient 0 ligne.

    J'imagine donc que j'ai bon. Mais je préfère avoir un avis extérieur

    Ma requête est-elle bonne ?

    Merci d'avance

  11. #11
    Modérateur
    Avatar de escartefigue
    Homme Profil pro
    bourreau
    Inscrit en
    Mars 2010
    Messages
    10 129
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : bourreau
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2010
    Messages : 10 129
    Points : 38 516
    Points
    38 516
    Billets dans le blog
    9
    Par défaut
    181 lignes de part et d'autres c'est bien mais...

    Dans la requête access, la 7ème colonne est Tbl_TP.[Description de l'intervention], vous n'avez pas conservé cette colonne, est-ce volontaire ?
    Vous n'avez pas non plus conservé la colonne Caractéristiques de l'intervention
    Les colonnes qui concernent l'intervenant ont également été supprimées (société, nom, gsm, mail)...

    Sinon, profitez en pour mettre en forme votre requête : une seule colonne par ligne et suppression des parenthèses inutiles (celles du where ne servent à rien, il y en a quand même 3 couches !)

    Et dans la mesure du possible, renommez vos tables et colonnes pour vous débarrasser des caractères spéciaux (accents, blancs, n°, ? etc...)

  12. #12
    Membre éprouvé
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    956
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 956
    Points : 1 199
    Points
    1 199
    Par défaut
    Bonjour,
    Ca n'a pas l'air mal, mais tu as toujours des jointures externes, or je croyais que c'était ce que tu cherchais à supprimer.

    Dans ta requête, tu peux encore remplacer tes left join par des not exists, puisqu'il s'agit là encore d'une requête de non concordance.
    Cordialement
    Soazig

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. count() dans *plusieurs* LEFT JOIN
    Par silver_dragoon dans le forum Langage SQL
    Réponses: 2
    Dernier message: 28/06/2004, 17h20
  2. LEFT JOIN avec Oracle 8i ne va pas... doit utiliser (+)
    Par loikiloik dans le forum Langage SQL
    Réponses: 10
    Dernier message: 21/04/2004, 16h38
  3. Interbase et left join
    Par Zog dans le forum Bases de données
    Réponses: 4
    Dernier message: 23/03/2004, 08h55
  4. Non coincident MySQL (Left Join)
    Par Remiguel dans le forum Requêtes
    Réponses: 6
    Dernier message: 03/11/2003, 21h25
  5. Export d'une vue avec LEFT JOIN
    Par schnourf dans le forum MS SQL Server
    Réponses: 3
    Dernier message: 22/05/2003, 13h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo