我让下表说“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/