mysql search for a catid in a text field

半腔热情 提交于 2019-12-06 07:26:59

MySQL can help you workaround this huge database design errors with function FIND_IN_SET. Give this a try:

SELECT * FROM articlepix 
WHERE published = 1 AND FIND_IN_SET('86', catid) > 0
ORDER BY RAND() LIMIT 1

Which of course can be simplified into:

WHERE published = 1 AND FIND_IN_SET('86', catid)

As the function only returns 0 when there is no match, but it might be harder to understand what it does :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!