Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Datensatz einfügen, falls nicht vorhanden, ohne eindeutigen Schlüssel

suchst du das ?

BEARBEITEN:

 INSERT INTO `clicks` (
  `id` ,
  `file_id` ,
  `country` ,
  `date` ,
  `timeClick` ,
  `user_subid`
 )
 SELECT `id` ,
`file_id` ,
`country` ,
`date` ,
`timeClick` ,
`user_subid`
FROM  
 (SELECT NULL id , '1500' `file_id` , 'Canada' `country` , '2014-05-24' `date` , '1400934475' `timeClick` , '7c282b9227328778680d5826e01f6d' `user_subid`) a 
LEFT JOIN `clicks` b ON 
  a.id = b.id AND a.`file_id` = b.`file_id` AND a.`user_subid` = b.`user_subid` 
WHERE b.`user_subid` IS NULL;

oder mit NOT EXIST

  INSERT INTO `clicks` (
  `id` ,
  `file_id` ,
  `country` ,
  `date` ,
  `timeClick` ,
  `user_subid`
 )
 SELECT `id` ,
`file_id` ,
`country` ,
`date` ,
`timeClick` ,
`user_subid`
FROM  
 (SELECT NULL id , '1500' `file_id` , 'Canada' `country` , '2014-05-24' `date` , '1400934475' `timeClick` , '7c282b9227328778680d5826e01f6d' `user_subid`) a
 WHERE NOT EXISTS (
   SELECT 1 
   FROM `clicks` 
   WHERE `user_subid` = '7c282b9227328778680d5826e01f6d')