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

Requêtes MySQL Discussion :

MySQL - distinct et grouper des colonnes


Sujet :

Requêtes MySQL

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2012
    Messages
    135
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2012
    Messages : 135
    Points : 69
    Points
    69
    Par défaut MySQL - distinct et grouper des colonnes
    bonjour,

    j'ai la requête suivante qui me permet de rechercher des enregistrements liés et de ressortir les id dont j'ai besoin pour faire un update.

    SELECT t1.ged_struct_id, t2.ged_struct_id, t3.ged_struct_id
    FROM `da_ged_struct` AS t1
    INNER JOIN da_ged_struct AS t2 ON t2.ged_struct_parent = t1.ged_struct_id
    INNER JOIN da_ged_struct AS t3 ON t3.ged_struct_parent = t2.ged_struct_id
    WHERE t1.ged_struct_parent = '391599'
    J'obtiens le résultat suivant avec 3 colonnes contenant chacune les id :

    ged_struct_id ged_struct_id ged_struct_id
    391600 391601 762555
    391600 391601 774527
    391600 391601 882974
    391600 391601 986461
    391600 391601 1090132
    391600 391602 765548
    391600 391602 777520
    391600 391602 885988
    391600 391603 768541
    391600 391603 780513
    391600 391603 889002
    391600 391604 771534
    391600 391604 783506
    391600 391604 901058
    391600 867903 870917
    391600 867903 873931
    391600 867903 879959
    391600 867903 895030
    391600 1173075 1176395
    391600 1173075 1179715
    391600 1173075 1183035
    391600 1173075 1186355
    391600 1173075 1189675
    391600 2483318 2491132
    391600 2483318 2498946
    391600 2483318 2506760
    391600 2483318 2514574
    391600 2483318 2522388
    391605 746833 746835
    391605 746833 746839

    Je souhaiterais obtenir non pas 3 colonnes mais une seule colonne contenant les id sans doublons.

    J'ai essayé la chose suivante avec un distinct mais ça ne marche pas.

    SELECT DISTINCT(t1.ged_struct_id, t2.ged_struct_id, t3.ged_struct_id) AS ged_struct_id
    FROM `da_ged_struct` AS t1
    INNER JOIN da_ged_struct AS t2 ON t2.ged_struct_parent = t1.ged_struct_id
    INNER JOIN da_ged_struct AS t3 ON t3.ged_struct_parent = t2.ged_struct_id
    WHERE t1.ged_struct_parent = '391599'

  2. #2
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2011
    Messages
    445
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Juin 2011
    Messages : 445
    Points : 622
    Points
    622
    Par défaut
    Peut être comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    SELECT t1.ged_struct_id
    FROM `da_ged_struct` AS t1
    WHERE t1.ged_struct_parent = '391599'
    UNION
    SELECT t2.ged_struct_id
    FROM `da_ged_struct` AS t1
    INNER JOIN da_ged_struct AS t2 ON t2.ged_struct_parent = t1.ged_struct_id
    WHERE t1.ged_struct_parent = '391599'
    UNION
    SELECT t3.ged_struct_id
    FROM `da_ged_struct` AS t1
    INNER JOIN da_ged_struct AS t2 ON t2.ged_struct_parent = t1.ged_struct_id
    INNER JOIN da_ged_struct AS t3 ON t3.ged_struct_parent = t2.ged_struct_id
    WHERE t1.ged_struct_parent = '391599'

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Février 2012
    Messages
    135
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2012
    Messages : 135
    Points : 69
    Points
    69
    Par défaut
    Merci beaucoup.

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

Discussions similaires

  1. [XL-2010] Grouper des colonnes et nommer ce groupe
    Par marylouou dans le forum Excel
    Réponses: 1
    Dernier message: 01/08/2016, 10h18
  2. Export Excel : Figer - Grouper des colonnes ?
    Par Vincent11alz dans le forum BIRT
    Réponses: 1
    Dernier message: 22/04/2014, 16h20
  3. Grouper des colonnes
    Par jerems113 dans le forum Cognos
    Réponses: 0
    Dernier message: 06/09/2010, 09h00
  4. [Mysql] Grouper des données dans 2 tables différentes
    Par jey350 dans le forum Langage SQL
    Réponses: 3
    Dernier message: 17/11/2006, 11h02
  5. [Débutant] DISTINCT sur une seule des colonnes ?
    Par Neilos dans le forum Langage SQL
    Réponses: 9
    Dernier message: 23/06/2004, 23h04

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