我有一个搜索,通过多个表中的几个列搜索匹配项。问题是我正在使用“OR”,但如果用户搜索多个列,这将不起作用。
这是我的查询:
SELECT clients.clientName,
projects.Client_ID,
projects.projectNumber,
projects.projectName,
projects.projectManager,
projects.expectedDate,
projects.address,
projects.CreationDate,
projects.custom1,
projects.custom2,
projects.custom3,
projects.custom4,
projects.custom5,
projects.custom6,
projects.custom7,
projects.custom8,
projects.custom9,
projects.Status_ID,
statuses.status
FROM projects
JOIN clients ON projects.Client_ID = clients.Client_ID
JOIN statuses ON projects.Status_ID = statuses.Status_ID
WHERE clientName LIKE '%$keyword%'
OR projectNumber LIKE '%$keyword%'
OR projectName LIKE '%$keyword%'
OR address LIKE '%$keyword%'
OR area LIKE '%$keyword%'
OR status LIKE '%$keyword%'
OR custom1 LIKE '%$keyword%'
OR custom2 LIKE '%$keyword%'
OR custom3 LIKE '%$keyword%'
OR custom4 LIKE '%$keyword%'
OR custom5 LIKE '%$keyword%'
OR custom6 LIKE '%$keyword%'
OR custom7 LIKE '%$keyword%'
OR custom8 LIKE '%$keyword%'
OR custom9 LIKE '%$keyword%';
如果用户搜索:状态和客户端 --my 查询将不会返回任何结果。
另外,我担心这个查询的速度有很多数据。