MySQL检查是否存在多行

MySQL检查是否存在多行

本文介绍了MySQL检查是否存在多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Here you can find how to check row existance:
SELECT EXISTS(SELECT 1 FROM table1 WHERE some_condition);

如何有效地存在表中的多行,如:

How to efficiently existance of multiple rows from table like:

SELECT EXISTS(SELECT 1 FROM table1 WHERE key = 0);
SELECT EXISTS(SELECT 1 FROM table1 WHERE key = 2);

来自表格:

key,username
0,foo
1,bar
2,boo

仅在找到两行(键0和2)时才返回正值?

to return positive only if both rows (with key 0 and 2) was found?

推荐答案

SELECT count(distinct key) = 2  FROM table1 WHERE key in (0, 2)

这篇关于MySQL检查是否存在多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:37