问题
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