mysql 插入数据 ,存在跳过

INSERT INTO table(value1, value2) 
SELECT 具体数据, 具体数据
FROM DUAL WHERE NOT EXISTS(SELECT value1,value2 FROM table WHERE value1= ?);

 

sql = 'UPDATE user SET first_name=%s, last_name=%s, affiliation=%s, keywords=%s, gender=%s WHERE user_id=%s'

sql = '''
        INSERT INTO user(user_id,first_name,last_name,affiliation,keywords,gender) VALUES (%s,%s,%s,%s,%s,%s)
        ON DUPLICATE KEY UPDATE first_name=VALUES(first_name), last_name=VALUES(last_name),
        affiliation=VALUES(affiliation), keywords=VALUES(keywords), gender=VALUES(gender)
    '''

 

posted @ 2020-07-20 13:26  薄荷味日记  阅读(839)  评论(0编辑  收藏  举报