SQL在搜索不同列时忽略WHERE

Sjr*_*ile 2 mysql sql where sql-like

我有一个忽略WHERE函数部分的SQL查询.

SELECT col1, col2, col3, col4
FROM table
WHERE col1 = 'yes'
AND col2 = 'no'
AND col3 || col4
LIKE '%maybe%'
Run Code Online (Sandbox Code Playgroud)

如果没有最后一个AND函数,它会返回正确的行,但是使用LIKE函数会返回带有"no"的行col1.

Mik*_*keb 6

我打算猜测你打算LIKE分发这个陈述 - 在这种情况下你想要:

SELECT col1, col2, col3, col4
FROM table
WHERE col1 = 'yes'
AND col2 = 'no'
AND (col3 LIKE '%maybe%'  OR col4 LIKE '%maybe%')
Run Code Online (Sandbox Code Playgroud)