gpt4 book ai didi

mysql - 如何检查数据库表中是否存在某个元素?

转载 作者:行者123 更新时间:2023-11-29 13:33:45 31 4
gpt4 key购买 nike

我是这个数据库的新手,我遇到了一个问题。我有一个查询返回多行作为输出。我想根据条件检查查询是否返回值。我正在使用 MySQL 和存储过程。

CREATE PROCEDURE getSearchFilter(IN searchname varchar(220),categoryid int, categoryheading varchar(220),catdiscription varchar(220))
DETERMINISTIC
BEGIN
if SELECT IF( EXISTS(SELECT distinct categorie_heading FROM product_meta_data WHERE categorie_heading='material'), 1, 0) then

//code
else
//code
end if;

END

SELECT distinct categorie_heading FROM product_meta_data WHERE categorie_heading='material';

它返回多行,但我想检查表中是否存在“ Material ”。

最佳答案

如果表中存在该值,以下查询将返回 1:

SELECT DISTINCT 1 FROM product_meta WHERE categorie_heading="material";

如果该列至少有一行包含“material”,则返回 1,否则返回 null。

关于mysql - 如何检查数据库表中是否存在某个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19051569/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com