par
VaN » 05 avr. 2010, 22:21
Bonjour,
Voici les 2 tables utilisées pour ma requête :
CREATE TABLE IF NOT EXISTS `labels` (
`label_id` int(11) NOT NULL AUTO_INCREMENT,
`label_date` date NOT NULL,
`label_nom` varchar(100) NOT NULL,
`label_limite` date NOT NULL,
`label_annee` year(4) NOT NULL,
`label_participations_max_je` tinyint(4) NOT NULL,
`label_statut` tinyint(4) NOT NULL,
PRIMARY KEY (`label_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `labels_inscriptions` (
`inscription_id` int(11) NOT NULL AUTO_INCREMENT,
`inscription_label_id` int(11) NOT NULL,
`inscription_je_id` int(11) NOT NULL,
`inscription_dossier_partenaires` varchar(100) NOT NULL,
`inscription_dossier_cnje` varchar(100) NOT NULL,
`inscription_statut` tinyint(4) NOT NULL,
PRIMARY KEY (`inscription_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
La liaison entre les deux tables se fait entre le champ label_id de la table labels et le champ inscription_label_id de la table labels_inscriptions
Et voici la requête qui poste problème :
SELECT label_id, label_nom, label_participations_max_je, COUNT(inscription_id) AS nb_inscriptions FROM labels
LEFT JOIN labels_inscriptions ON inscription_label_id = label_id AND inscription_je_id = 1
WHERE label_statut = 1
Je souhaiterai modifier ma requête pour ne pas récupérer les labels qui ont déjà un nombre d'inscriptions maximum, c'est à dire les labels dont le champ label_participations_max_je est = à COUNT(inscription_id) sur la table labels_inscriptions.
Puis-je faire cela en une seule requête ?
Bonjour,
Voici les 2 tables utilisées pour ma requête :
[quote]
CREATE TABLE IF NOT EXISTS `labels` (
`label_id` int(11) NOT NULL AUTO_INCREMENT,
`label_date` date NOT NULL,
`label_nom` varchar(100) NOT NULL,
`label_limite` date NOT NULL,
`label_annee` year(4) NOT NULL,
`label_participations_max_je` tinyint(4) NOT NULL,
`label_statut` tinyint(4) NOT NULL,
PRIMARY KEY (`label_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE IF NOT EXISTS `labels_inscriptions` (
`inscription_id` int(11) NOT NULL AUTO_INCREMENT,
`inscription_label_id` int(11) NOT NULL,
`inscription_je_id` int(11) NOT NULL,
`inscription_dossier_partenaires` varchar(100) NOT NULL,
`inscription_dossier_cnje` varchar(100) NOT NULL,
`inscription_statut` tinyint(4) NOT NULL,
PRIMARY KEY (`inscription_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;[/quote]
La liaison entre les deux tables se fait entre le champ label_id de la table labels et le champ inscription_label_id de la table labels_inscriptions
Et voici la requête qui poste problème :
[sql]SELECT label_id, label_nom, label_participations_max_je, COUNT(inscription_id) AS nb_inscriptions FROM labels
LEFT JOIN labels_inscriptions ON inscription_label_id = label_id AND inscription_je_id = 1
WHERE label_statut = 1[/sql]
Je souhaiterai modifier ma requête pour ne pas récupérer les labels qui ont déjà un nombre d'inscriptions maximum, c'est à dire les labels dont le champ label_participations_max_je est = à COUNT(inscription_id) sur la table labels_inscriptions.
Puis-je faire cela en une seule requête ?