SET SELECT 与 SELECT INTO 之间的区别

Difference between SET with SELECT vs SELECT INTO

这两个查询有区别吗?两者都正确吗?

SET price = (SELECT buyPrice FROM products WHERE productCode = product);

SELECT buyPrice INTO price FROM products WHERE productCode = product;

两者都正确。

使用 SET 语法,一次只能设置一个变量,因此 SELECT 查询在其 select-list.

中必须只有一个表达式

使用SELECT INTO 语法,您可以设置多个变量。例如:

SELECT buyPrice, lastUpdated INTO price, latest FROM products ...