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)

http://i.imgur.com/rKrRBQ8g.png


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)

http://i.imgur.com/unkURL5.png

(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) )


Server

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 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计