[英]Mysql how to select row where field's array contains this value
我有這個表結構“帖子”
+----+-------+---------------+
| id | post | authors_ids |
+----+-------+---------------+
| 1 | test1 | ["1","2"] |
+----+-------+---------------+
| 2 | test2 | ["1","3"] |
+----+-------+---------------+
| 3 | test3 | ["3","4","5"] |
+----+-------+---------------+
我想要做的是選擇在authors_ids
字段中包含特定值的行,例如我需要選擇authors_ids 數組包含數字4
的帖子
我知道表結構是錯誤的,但此時我將無法更改它。
我怎樣才能做到這一點?
實現此目的的一種快速方法是使用LIKE
進行選擇:
SELECT * FROM `posts` WHERE `authors_ids` LIKE '%"4"%';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.