我的初始插入语句工作正常,但我想将自定义结果发送回我的应用程序。 这可能吗? (参见下面的最后一条SELECT语句):
-- this is working
INSERT INTO users (email, firstName, lastName, password)
SELECT * FROM (
SELECT '{{email}}' as email,
'test' as firstName,
'person' as lastName,
'{{password}}' as password) AS tmp
WHERE NOT EXISTS (
SELECT email FROM users WHERE email = '{{email}}'
) LIMIT 1;
-- this statement is not working.
SELECT IF(ROW_COUNT() > 0,
SELECT * FROM users WHERE email = '{{email}}',
'failure'
);
运行它给了我:
错误详细信息:SQL语法中存在错误;查看与您的MySQL服务器版本相对应的手册,以便在#&...; SELECT * FROM users附近使用正确的语法WHERE email =' d@gmail.com',' failure' )'在第2行
答案 0 :(得分:0)
我认为你要做的事情是:
SELECT IF(
(SELECT COUNT(*) FROM users WHERE email = '{{email}}') > 0,
'success',
'false'
);
答案 1 :(得分:0)
用这个替换最后一个查询:
SELECT * FROM users WHERE `id`= LAST_INSERT_ID()