SELECT `post`.*, `user_account`.`project_name`
FROM
`post`
INNER JOIN `user_account` ON `post`.`user_id` = `user_account`.`user_id`
WHERE
`post`.`deleted_at` IS NULL
AND `is_active` = 1
AND `deleted_at` IS NULL
AND `end` > '2013-10-09'
AND `user_account`.`project_name` LIKE '%intensiivkursus%'
OR (
`title` LIKE '%intensiivkursus%'
OR `topics` LIKE '%intensiivkursus%'
OR `target_group` LIKE '%intensiivkursus%'
OR `lectors` LIKE '%intensiivkursus%'
OR `timetable` LIKE '%intensiivkursus%'
)
GROUP BY
`post`.`id`
ORDER BY
`post`.`created_at` DESC


我希望这只会对is_active = 1给出结果,但是由于某些原因,它会给出相反的结果。我得到5个结果,全部与is_active = 0
我在这里想念什么?

最佳答案

我怀疑您的OR / AND和括号存在问题。运算符的优先级会造成混乱。

你不是说

AND
(`user_account`.`project_name` LIKE '%intensiivkursus%'
OR `title` LIKE '%intensiivkursus%'
OR `topics` LIKE '%intensiivkursus%'
OR `target_group` LIKE '%intensiivkursus%'
OR `lectors` LIKE '%intensiivkursus%'
OR `timetable` LIKE '%intensiivkursus%'
)


或许

AND `user_account`.`project_name` LIKE '%intensiivkursus%'
AND (
`title` LIKE '%intensiivkursus%'
OR `topics` LIKE '%intensiivkursus%'
OR `target_group` LIKE '%intensiivkursus%'
OR `lectors` LIKE '%intensiivkursus%'
OR `timetable` LIKE '%intensiivkursus%'
)

09-25 21:12