I have below search script to perform multiple column search in table, but the results is not as expected, few of data rows are show with status = new
and company name = demo
, can someone please point out what is wrong for below query? what is more accurate query to perform a search with these conditions?
SELECT * FROM messageboard AS m LEFT JOIN users AS u ON m.author_id=u.user_id
WHERE m.status='approved'
AND u.user_email LIKE '%demo%'
OR u.company_name LIKE '%demo%'
OR m.subject LIKE '%demo%'
ORDER BY m.posted_time DESC
Thanks a lot.
SELECT * FROM messageboard AS m LEFT JOIN users AS u ON m.author_id=u.user_id
WHERE m.status='approved'
AND (u.user_email LIKE '%demo%'
OR u.company_name LIKE '%demo%'
OR m.subject LIKE '%demo%' )
ORDER BY m.posted_time DESC
我建议用方括号组织您的AND和OR条件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.