0

Can someone tell me, why the first query executes fine, but the second query gives as error. It even gives error with empty table

#1060 - Duplicate column name '3'.

FIRST QUERY - OK

INSERT INTO `ps_category_product` (`id_category`, 
                                   `id_product`, 
                                   `position`
                                   ) 
SELECT * FROM (SELECT '3','41895','2') AS tmp 
WHERE NOT EXISTS ( SELECT * FROM `ps_category_product` 
                            WHERE id_category =3 AND id_product =41895);

SECOND QUERY - ERROR

INSERT INTO `ps_category_product` (`id_category`, 
                                   `id_product`, 
                                   `position`
                                   ) 
SELECT * FROM (SELECT '3','116059','3') AS tmp 
WHERE NOT EXISTS ( SELECT * FROM `ps_category_product` 
                            WHERE id_category =3 AND id_product =116059
                 );

estructure of table

Ergest Basha
  • 7,870
  • 4
  • 8
  • 28
Jonatan
  • 45
  • 5

0 Answers0