[英]php mysql select data where column array
我在數據庫articles表中:
id- cat - title
1- 10,2 - the title
2- 5,10 - the title
3- 7 - the title
4- 7,4,3 - the title
我想選擇cat = '10'
的文章,這意味着article id 1 and 2
。
我使用過MySQL LIKE
但效果不佳。
任何想法 ?
select * from your_table
where find_in_set(10, cat) > 0
但實際上,更好的解決方案是對表進行規范化,並在列中僅存儲一個值!
您可以通過添加另一個表來做到這一點
article_categories table
------------------------
article_id
category_id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.