MySQL Forums
Forum List  »  Newbie

Duplicate error message on temporary table
Posted by: Bob Bakker
Date: November 23, 2014 02:56PM

Hello everyone,

Thanks to Mysql.com for providing this forum. I have a question.
I have a code that checks if a certain record exists in the database. If not, it will add the records, if it already exists it should skip the record.

Its run by PHP but for the sake of the argument (haha) i've made it a regular mysql code here. The problem is, the code works fine if every records is diffrent from the other ones. But if one is the same as a diffrent record in the same query, it gives me an '#1060 - Duplicate column name' error and I can't figure out why.

So this works:


INSERT INTO `Overnames_New` 
            (`nieuwe_eigenaar`, 
             `nieuwe_alliantie`) 

SELECT * 
FROM   (SELECT "var1", 
               "var2") AS tmp 

WHERE  NOT EXISTS (SELECT *  from `Overnames_New`
                   WHERE  nieuwe_eigenaar = "var1" 
                   AND `nieuwe_alliantie` = "var2") 
LIMIT 1

And this does not:



INSERT INTO `Overnames_New` 
            (`nieuwe_eigenaar`, 
             `nieuwe_alliantie`) 

SELECT * 
FROM   (SELECT "var1", 
               "var1") AS tmp 

WHERE  NOT EXISTS (SELECT *  from `Overnames_New`
                   WHERE  nieuwe_eigenaar = "var1" 
                   AND `nieuwe_alliantie` = "var1") 
LIMIT 1




What am I doing wrong? I hope you guys can help.

Thanks in advcance!

Options: ReplyQuote


Subject
Written By
Posted
Duplicate error message on temporary table
November 23, 2014 02:56PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.