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!