oberton Posted January 26, 2014 Share Posted January 26, 2014 Bonjour J'ai un millier de produits qui sont dans 1 ou 2 categories existantes. J'ai recree une trentaine de nouvelles categories. J'aimerai ajouter une 3e categorie a ces produits. Par exemple, produit A appartient deja a cat 3 et 4, je voudrais qu'il appartienne en plus a 5 si il appartient a 2. Existe t'il une requete SQL qui ferait ca: si produit X appartient a cat Y, rajouter une entree pour qu'il soit aussi associe a Z? Sachant que l'association se fait dans ps_category_product avec une ligne par categorie pour le meme produit: id_product 10885 id_category 86 id_product 10885 id_category 35 Il faudrait donc selectioner tous les n id_produits pour id_category = Y et faire un insert dans la table pour que les n id_produits avec id_category = Z Si un pro du SQL traine par ici, merci du coup de main! Sinon si quelqu'un a une autre idee pour faire ca je suis aussi preneur. Link to comment Share on other sites More sharing options...
oberton Posted January 26, 2014 Author Share Posted January 26, 2014 Je pensai me rapprocher avec: SELECT `id_product` FROM `ps_category_product` WHERE `id_category`=200; INSERT INTO `ps_category_product` (`id_product`,`id_category`) VALUES (`id_product`,203); Mais j'ai une erreur : #1062 - Duplicate entry '203-0' for key 'PRIMARY' Link to comment Share on other sites More sharing options...
oberton Posted January 26, 2014 Author Share Posted January 26, 2014 C'est bon, ca ma permis de reviser mon SQL: INSERT INTO ps_category_product (`id_category`, `id_product`, `position`) SELECT 202, `id_product`, `position` FROM ps_category_product WHERE `id_category`= 200 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now