dongzhong3688 2016-06-22 07:32 采纳率: 0%
浏览 14


Hey all i am working on a database project for a class (im just learning sql)

What i am doing successfully

1: Reading an event XML feed from another website and placing it into the database (via php)

(internal id is controlled by me and needed externalinstance_id is pulled from the feed and i want it to insert if not exists)

what am i trying to do?

1: The events have their own eventinstance_id (i want to use this to insert only unique) , and i Have my own Internal ID, how do i "insert if external_id is not in the database" (ignore duplicated)

what i tried so far:

1: A select where not exists in phpmyadmin(trying to build the query) however when i perform the query i get this error on phpmyadmin

*different table same idea (my testing table)

(i want to insert iff there isnt a internal_id of 2 for example... (same project different table same idea of what i need to do) )


Win 7 (i know)

Apache 2.4.18

PHP 7.0.6

PHP EXT mysqli

phpmyadmin 4.5.1

Thanks in advanced (may or may not be a stupid question)

  • 写回答

1条回答 默认 最新

  • dpvp56187 2016-06-22 07:37

    Make eventinstance_id as Unique Id and use can use "INSERT IGNORE" QUERY. It will insert only unique values.

    Example :- INSERT IGNORE INTO table (pid,uid,data) VALUES (1,34,56); Where pid is primary key and uid is unique key.

    Below you can find more details on Insert Ignore "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 关于网上一个easyx制作的见缝插针小游戏(c++)
    • ¥15 开地址法双散列函数处理碰撞
    • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
    • ¥15 联通光猫掉注册了怎么重新注册上去
    • ¥15 关于unity开发steamvr程序遇到的问题
    • ¥60 求tc downloader的下载方式
    • ¥15 华为 快捷方式 手电筒 接口
    • ¥15 Qt6.5支不支持Android13开发啊
    • ¥20 网络只能跑一半,应该如何设置
    • ¥20 Python调用百度开发者平台人脸识别接口