我目前使用SELECT而不是VALUES的方式插入數據,因爲它是默認的。問題是,我找不到只有在數據庫中才插入數據的方法。只有在不存在的情況下插入MYSQL
這是我當前的查詢:
INSERT INTO collectives_users(id_user,id_artistname,id_collective,users_type,status)
SELECT
(SELECT id_user FROM artistnames WHERE artistname = 'yoannis'),
(SELECT id FROM artistnames WHERE artistname = 'yoannis'),
('1'),(2),(0)
UNION ALL
SELECT
(SELECT id_user FROM artistnames WHERE artistname = 'paul'),
(SELECT id FROM artistnames WHERE artistname = 'paul'),
('1'),(4),(0)
我
INSERT IGNORE INTO
不工作時,並沒有真正合適的(不返回錯誤)
試過我也試圖與
AND NOT EXIST
不起作用。
如果你有一個想法不要猶豫。
表中的獨特列是什麼? – 2013-05-04 15:48:35
嘗試像select * from(select ... union all select ...)_t where ... not in(select ... from collective_users)來嘗試給括號加上括號 – 2013-05-04 15:51:10
@JW你的意思是主鍵。 – Juampi 2013-05-04 15:58:45