简体   繁体   中英

Mysql how to select row where field's array contains this value

i have this table structure "posts"

+----+-------+---------------+
| id | post  | authors_ids   |
+----+-------+---------------+
| 1  | test1 | ["1","2"]     |
+----+-------+---------------+
| 2  | test2 | ["1","3"]     |
+----+-------+---------------+
| 3  | test3 | ["3","4","5"] |
+----+-------+---------------+

what i want to do is to select rows that contains in authors_ids field a particular value for example i need to select the posts where authors_ids array contains number 4

i know that the table structure is wrong but at this time i will not be able to change it.

how can i achieve that ?

实现此目的的一种快速方法是使用LIKE进行选择:

SELECT * FROM `posts` WHERE `authors_ids` LIKE '%"4"%';

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM