mysql - 生成MYsql查询获取记录

标签 mysql

我让下表说“A”

"column1"   "column2"
   1         arafath@gmail.com
   2         ram@gmail.com;arafath@gmail.com
   3         tom@gmail.com

我想获取满足以下条件的记录。

条件 1: 如果列值存在于任何行中,它将检索匹配的行

条件2:
如果列值与任何行都不匹配,它要检索所有行

  Eg: column2 = "ram@gmail.com"
  Output should be "row 2"

  Eg: column2 = "arafath@gmail.com"
  Output should be "row 1, row 2"

  Eg: column2 = "xxx@gmail.com" (Unmatched column)
  Output should be all the rows (row 1, row 2, row 3)

请帮我解决这个问题。

提前致谢。

最佳答案

请尝试下面的。

SELECT col1, col2
FROM yourTable 
where ( not exists (Select col2
FROM yourTable where col2 like 'xxx@gmail.com') 
or col2 like 'xxx@gmail.com');

关于mysql - 生成MYsql查询获取记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55719884/

相关文章:

php - 配置 Azure 云服务上的 Wordpress 以通过 SSL 连接到 Azure MySQL

php - MySQL - 查找有或没有特殊字符的记录

c++ - 将 VS 32 位项目转换为 64 位项目

mysql - 当我在一个表中复制数据时出现sql语法错误

mysql - (我如何)使用证书将 Azure 数据工厂连接到(本地)mysql 数据库

java - Maven 的 JDBC 连接错误

mysql - 替代临时表

php - 将 JSON 数据插入 MySQL 表

php - PHP/MySQL 中的好友系统?

mysql - 如何从主机执行 MySQL 命令到运行 MySQL 服务器的容器?