sql LIKE语句由三个“喜欢”组合而成

时间:2013-07-25 13:26:04

标签: sql select sql-like

如何结合三个类似语句的sql查询?我试着这样:

SELECT * FROM myTable 
WHERE 
  (NAME LIKE '%someChars%' AND 
    (CITY LIKE '%someChars%' AND 
     TYPE LIKE'% someChars%')
  );

它不起作用,你能帮帮我吗?

2 个答案:

答案 0 :(得分:1)

除了Type是一个sql关键字之外,查询是正确的,所以请尝试将它放在括号之间:

SELECT * FROM [myTable] 
 WHERE ([NAME] LIKE '%someChars%' AND
        ([CITY] LIKE '%someChars%' AND
         [TYPE] LIKE '%someChars%'));

PS:不需要括号

答案 1 :(得分:0)

SELECT *
FROM myTable
WHERE
  NAME LIKE '%someChars%' AND
  CITY LIKE '%someChars%' AND
  TYPE LIKE '%someChars%';