MySQL: SELECT after INSERT IGNORE

拜拜、爱过 提交于 2019-12-25 14:45:08

问题


I have a simple table, containing memberIds for each Email.

CREATE TABLE `cu_members` (
  `memberID` int(6) unsigned zerofill NOT NULL AUTO_INCREMENT,
  `email` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`memberID`),
  UNIQUE KEY `email` (`email`)
)

The table allows a new memberId to be created for each new email address. I'm doing this using:

INSERT IGNORE INTO `cu_members` (email)
VALUES ("newemail@domain.com")

I can also do this using:

INSERT INTO `cu_members` (email)
VALUES ("newemail@domain.com")
ON DUPLICATE KEY UPDATE email="newemail@domain.com"

The problem is that I ALWAYS need to return a record from the query. I know a normal INSERT doesn't return a record, but i wondered if a different SQL statement might do so.

Why... I'm using Zapier to update a database. They only allow certain queries using their inbuilt libraries and the query must return an array or record/s.

Note: I can't call an external library or right a procedure outside of phpMyAdmin.

Is there a way to return a record for the email I was trying to insert?

Something like...

SELECT memberID FROM
    (
    INSERT IGNORE INTO `cu_members` (email)
    VALUES ("newemail@domain.com")
    )

来源:https://stackoverflow.com/questions/45854653/mysql-select-after-insert-ignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!