从多列

时间:2017-01-28 07:04:04

标签: mysql

我想删除其值包含%DJ%和%SD%字符的行。而且我希望此查询从两个不同的列进行检查。表格名称'位置',第一列名称' start_location'和第二列名称' end_location'。这是我想要执行的SQL查询:

DELETE FROM location WHERE start_location like '%DJ%' and start_location like '%SD%'

DELETE FROM location WHERE end_location like '%DJ%' and end_location like '%SD%'

所以我想在一个中执行此查询。

2 个答案:

答案 0 :(得分:0)

使用OR

DELETE FROM location
WHERE start_location like '%DJ%' or start_location like '%SD%'
or end_location like '%DJ%' or end_location like '%SD%';

答案 1 :(得分:0)

使用MySQL REGEXP运算符的简短解决方案:

DELETE FROM location 
WHERE start_location REGEXP 'DJ|SD' AND end_location REGEXP 'DJ|SD';

注意:如果要删除 列,请将AND替换为OR