这个说法有什么问题?
IF EXISTS (
SELECT *
FROM `apples`
WHERE `apples`.`color` = ?
AND `apples`.`size` = ?)
SELECT `apples`.`applesID`
ELSE
INSERT INTO `apples` (`color`, `size`)
VALUES(?,?);
这个说法有什么问题?
IF EXISTS (
SELECT *
FROM `apples`
WHERE `apples`.`color` = ?
AND `apples`.`size` = ?)
SELECT `apples`.`applesID`
ELSE
INSERT INTO `apples` (`color`, `size`)
VALUES(?,?);
您没有为IF使用正确的语法:
IF EXISTS (
SELECT *
FROM `apples`
WHERE `apples`.`color` = ?
AND `apples`.`size` = ?) THEN
SELECT `apples`.`applesID`;
ELSE
INSERT INTO `apples` (`color`, `size`) VALUES(?,?);
END IF;