par
Patriboom » 25 janv. 2008, 08:00
Voici, avec les vraies requêtes, les résultats que j'obtiens:
Code : Tout sélectionner
SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
C'est la requête orginale, qui trie aussi bien les PERS qui ont un prof. que les PERS sans prof.
La première version de modification est celle-ci:
Code : Tout sélectionner
SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY CASE
WHEN INSCR.id_anim = 0 PERS.Naissance, PERS.Nom
ELSE INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
Et voici le résultat:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PERS.Naissance , PERS.Nom ELSE INSCR.id_anim ASC , PERS.Nom ASC , PERS.Prenom AS' at line 1
Voici une deuxième version essayée:
Code : Tout sélectionner
SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
CASE
WHEN INSCR.id_anim = 0 ORDER BY PERS.Naissance, PERS.Nom
ELSE ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
et son code d'erreur
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN INSCR.id_anim = 0 ORDER BY PERS.Naissance , PERS.Nom ELSE ORDER BY INS' at line 1
Il me semble que le premier code d'erreur annonce une proximité de la solution.
Voici une troisième tentative, avec IF, celle-là:
Code : Tout sélectionner
SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY
IF (INSCR.id_anim = 0) PERS.Naissance, PERS.Nom
ELSE ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
et son code d'erreur:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') PERS.Naissance , PERS.Nom ELSE ORDER BY INSCR.id_anim ASC , PERS.Nom ASC , PER' at line 1
Et si j'enlève les parenthèses:
Code : Tout sélectionner
SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY
IF INSCR.id_anim == 0 THEN PERS.Naissance, PERS.Nom
ELSE ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
et le code d'erreur:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSCR.id_anim == 0 THEN PERS.Naissance, PERS.Nom ELSE ORDER BY INSCR.id_anim AS' at line 10 (en plus de me dire que la ponctuation n'est pas correcte) avec = ou ==, même résultat.
Avec des accolades pour délimiter les réponses, il n'y a pas de meilleurs résultats.
Quelqu'un aurait d'autres idées?
Merci à l'avance
Voici, avec les vraies requêtes, les résultats que j'obtiens:
[code]SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
[/code]
C'est la requête orginale, qui trie aussi bien les PERS qui ont un prof. que les PERS sans prof.
La première version de modification est celle-ci: [code]SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY CASE
WHEN INSCR.id_anim = 0 PERS.Naissance, PERS.Nom
ELSE INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
[/code]
Et voici le résultat:
[color=red]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'PERS.Naissance , PERS.Nom ELSE INSCR.id_anim ASC , PERS.Nom ASC , PERS.Prenom AS' at line 1 [/color]
Voici une deuxième version essayée: [code]SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
CASE
WHEN INSCR.id_anim = 0 ORDER BY PERS.Naissance, PERS.Nom
ELSE ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
[/code]et son code d'erreur [color=red]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN INSCR.id_anim = 0 ORDER BY PERS.Naissance , PERS.Nom ELSE ORDER BY INS' at line 1 [/color]
Il me semble que le premier code d'erreur annonce une proximité de la solution.
Voici une troisième tentative, avec IF, celle-là: [code]SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY
IF (INSCR.id_anim = 0) PERS.Naissance, PERS.Nom
ELSE ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
[/code]et son code d'erreur: [color=red]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') PERS.Naissance , PERS.Nom ELSE ORDER BY INSCR.id_anim ASC , PERS.Nom ASC , PER' at line 1[/color]
Et si j'enlève les parenthèses:
[code]SELECT
PERS.id_perso AS id_perso, CONCAT(PERS.Prenom, " ", PERS.Nom) AS Nom, PERS.Naissance AS Naissance,
INSCR.id_inscr, INSCR.id_anim AS ParQui,
CONCAT(ANIM.Prenom, " ", ANIM.Nom) AS Animateur
FROM paroisses_inscriptions AS INSCR
LEFT JOIN paroisses_personnes AS PERS ON PERS.id_perso = INSCR.id_perso
LEFT JOIN paroisses_personnes AS ANIM ON ANIM.id_perso = INSCR.id_anim
WHERE INSCR.id_acti = 113
AND INSCR.active = 'oui'
ORDER BY
IF INSCR.id_anim == 0 THEN PERS.Naissance, PERS.Nom
ELSE ORDER BY INSCR.id_anim ASC, PERS.Nom ASC, PERS.Prenom ASC
END
[/code] et le code d'erreur: [color=red]#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSCR.id_anim == 0 THEN PERS.Naissance, PERS.Nom ELSE ORDER BY INSCR.id_anim AS' at line 10 [/color] (en plus de me dire que la ponctuation n'est pas correcte) avec = ou ==, même résultat.
Avec des accolades pour délimiter les réponses, il n'y a pas de meilleurs résultats.
Quelqu'un aurait d'autres idées?
Merci à l'avance