Recherche sur plusieurs tables SQL
Résolu
2pax.cruz
-
Autumn`Tears Messages postés 1054 Date d'inscription Statut Membre Dernière intervention -
Autumn`Tears Messages postés 1054 Date d'inscription Statut Membre Dernière intervention -
A voir également:
- Recherche sur plusieurs tables SQL
- Recherche automatique des chaînes ne fonctionne pas - Guide
- Tables des matières word - Guide
- Rechercher ou entrer l'adresse mm - recherche google - Guide
- Recherche photo - Guide
- Je recherche une chanson - Guide
5 réponses
SELECT * FROM Promotion WHERE categorie = 'qqch' AND enseigne = ANY (SELECT id FROM Enseigne WHERE province = 'qqch')
Pas testé mais ça devrait fonctionner sinon donne les erreurs et on verra ;)
Pas testé mais ça devrait fonctionner sinon donne les erreurs et on verra ;)
Salut,
essaie SELECT * FROM Promotion WHERE categorie=ta_categorie AND enseigne IN(SELECT id FROM Enseigne WHERE province='ta_province')
essaie SELECT * FROM Promotion WHERE categorie=ta_categorie AND enseigne IN(SELECT id FROM Enseigne WHERE province='ta_province')
Mais quels génies! Merci!
Je me permets de poser une autre question :)
Je n'arrive pas à créer de clef étrangère entre mes tables (champs enseigne.id et promotion.enseigne). Il me dit de vérifier les types de données, cependant, ce sont tous des int.
Je vous copie-colle les structures :
CREATE TABLE 'enseigne' (
'id' int(11) unsigned NOT NULL AUTO_INCREMENT,
'nom' varchar(20) NOT NULL,
'adresse' tinytext NOT NULL,
'coordonnees' varchar(19) NOT NULL,
'codepostal' varchar(4) NOT NULL,
'ville' tinytext NOT NULL,
'province' varchar(4) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE KEY 'coordonnees' ('coordonnees')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE 'promotion' (
'id' int(11) unsigned NOT NULL AUTO_INCREMENT,
'enseigne' int(11) NOT NULL,
'categorie' varchar(8) NOT NULL,
'produit' tinytext NOT NULL,
'reduction_type' varchar(4) NOT NULL,
'reduction' tinytext NOT NULL,
PRIMARY KEY ('id'),
KEY 'enseigne' ('enseigne')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Merci!
Je me permets de poser une autre question :)
Je n'arrive pas à créer de clef étrangère entre mes tables (champs enseigne.id et promotion.enseigne). Il me dit de vérifier les types de données, cependant, ce sont tous des int.
Je vous copie-colle les structures :
CREATE TABLE 'enseigne' (
'id' int(11) unsigned NOT NULL AUTO_INCREMENT,
'nom' varchar(20) NOT NULL,
'adresse' tinytext NOT NULL,
'coordonnees' varchar(19) NOT NULL,
'codepostal' varchar(4) NOT NULL,
'ville' tinytext NOT NULL,
'province' varchar(4) NOT NULL,
PRIMARY KEY ('id'),
UNIQUE KEY 'coordonnees' ('coordonnees')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE 'promotion' (
'id' int(11) unsigned NOT NULL AUTO_INCREMENT,
'enseigne' int(11) NOT NULL,
'categorie' varchar(8) NOT NULL,
'produit' tinytext NOT NULL,
'reduction_type' varchar(4) NOT NULL,
'reduction' tinytext NOT NULL,
PRIMARY KEY ('id'),
KEY 'enseigne' ('enseigne')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Merci!
CREATE TABLE promotion (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
enseigne int(11) NOT NULL,
categorie varchar(8) NOT NULL,
produit tinytext NOT NULL,
reduction_type varchar(4) NOT NULL,
reduction tinytext NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (enseigne) REFERENCES Enseigne(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Cela devrait fonctionner.
Cordialement,
Adrien.
id int(11) unsigned NOT NULL AUTO_INCREMENT,
enseigne int(11) NOT NULL,
categorie varchar(8) NOT NULL,
produit tinytext NOT NULL,
reduction_type varchar(4) NOT NULL,
reduction tinytext NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (enseigne) REFERENCES Enseigne(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Cela devrait fonctionner.
Cordialement,
Adrien.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Cela ne fonctionne pas :(
#1005 - Can't create table 'globalads.promotion' (errno: 150) (<a href="server_engines.php?engine=InnoDB&page=Status&token=ec681c9a116da23601e97c1a08720624">Détails...</a>)
CREATE TABLE promotion(
id INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
enseigne INT( 11 ) NOT NULL ,
categorie VARCHAR( 8 ) NOT NULL ,
produit TINYTEXT NOT NULL ,
reduction_type VARCHAR( 4 ) NOT NULL ,
reduction TINYTEXT NOT NULL ,
PRIMARY KEY ( id ) ,
FOREIGN KEY ( enseigne ) REFERENCES Enseigne( id )
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Merci :D
#1005 - Can't create table 'globalads.promotion' (errno: 150) (<a href="server_engines.php?engine=InnoDB&page=Status&token=ec681c9a116da23601e97c1a08720624">Détails...</a>)
CREATE TABLE promotion(
id INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
enseigne INT( 11 ) NOT NULL ,
categorie VARCHAR( 8 ) NOT NULL ,
produit TINYTEXT NOT NULL ,
reduction_type VARCHAR( 4 ) NOT NULL ,
reduction TINYTEXT NOT NULL ,
PRIMARY KEY ( id ) ,
FOREIGN KEY ( enseigne ) REFERENCES Enseigne( id )
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Merci :D
Ah, peut-être que tu as besoin des guillemets alors...
CREATE TABLE 'promotion' (
'id int(11) unsigned NOT NULL AUTO_INCREMENT,
'enseigne' int(11) NOT NULL,
'categorie' varchar(8) NOT NULL,
'produit' tinytext NOT NULL,
'reduction_type' varchar(4) NOT NULL,
'reduction' tinytext NOT NULL,
PRIMARY KEY ('id'),
FOREIGN KEY ('enseigne') REFERENCES Enseigne('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE 'promotion' (
'id int(11) unsigned NOT NULL AUTO_INCREMENT,
'enseigne' int(11) NOT NULL,
'categorie' varchar(8) NOT NULL,
'produit' tinytext NOT NULL,
'reduction_type' varchar(4) NOT NULL,
'reduction' tinytext NOT NULL,
PRIMARY KEY ('id'),
FOREIGN KEY ('enseigne') REFERENCES Enseigne('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Je suis désolé mais cela ne fonctionne pas :
J'ai pourtant remis une simple quote après le id dans la requête que vous donnez car cette simple quote semblait manquante :s
#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 ''promotion' ( 'id' int(11) unsigned NOT NULL AUTO_INCREMENT, 'enseigne' int(' at line 1
CREATE TABLE 'promotion'(
'id'INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
'enseigne'INT( 11 ) NOT NULL ,
'categorie'VARCHAR( 8 ) NOT NULL ,
'produit'TINYTEXT NOT NULL ,
'reduction_type'VARCHAR( 4 ) NOT NULL ,
'reduction'TINYTEXT NOT NULL ,
PRIMARY KEY ( 'id' ) ,
FOREIGN KEY ( 'enseigne' ) REFERENCES Enseigne( 'id' )
) ENGINE = INNODB DEFAULT CHARSET = latin1;
J'ai pourtant remis une simple quote après le id dans la requête que vous donnez car cette simple quote semblait manquante :s
#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 ''promotion' ( 'id' int(11) unsigned NOT NULL AUTO_INCREMENT, 'enseigne' int(' at line 1
CREATE TABLE 'promotion'(
'id'INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT ,
'enseigne'INT( 11 ) NOT NULL ,
'categorie'VARCHAR( 8 ) NOT NULL ,
'produit'TINYTEXT NOT NULL ,
'reduction_type'VARCHAR( 4 ) NOT NULL ,
'reduction'TINYTEXT NOT NULL ,
PRIMARY KEY ( 'id' ) ,
FOREIGN KEY ( 'enseigne' ) REFERENCES Enseigne( 'id' )
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Je viens de tester de cette façon et ça semble fonctionner :
CREATE TABLE enseigne (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
nom varchar(20) NOT NULL,
adresse tinytext NOT NULL,
coordonnees varchar(19) NOT NULL,
codepostal varchar(4) NOT NULL,
ville tinytext NOT NULL,
province varchar(4) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY coordonnees (coordonnees)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE promotion (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
enseigne int(11) unsigned NOT NULL,
categorie varchar(8) NOT NULL,
produit tinytext NOT NULL,
reduction_type varchar(4) NOT NULL,
reduction tinytext NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (enseigne) REFERENCES enseigne(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE enseigne (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
nom varchar(20) NOT NULL,
adresse tinytext NOT NULL,
coordonnees varchar(19) NOT NULL,
codepostal varchar(4) NOT NULL,
ville tinytext NOT NULL,
province varchar(4) NOT NULL,
PRIMARY KEY (id),
UNIQUE KEY coordonnees (coordonnees)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE promotion (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
enseigne int(11) unsigned NOT NULL,
categorie varchar(8) NOT NULL,
produit tinytext NOT NULL,
reduction_type varchar(4) NOT NULL,
reduction tinytext NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (enseigne) REFERENCES enseigne(id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;