如何从数据库列中爆炸用户ID? [英] How to explode user id from a database column?

查看:94
本文介绍了如何从数据库列中爆炸用户ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表名消息.有一个列名receiver_id,我需要在 receiver_id = 4 的地方获取记录,但是我总是得到空输出.

I have a table name messages. There is a column name receiver_id I need to fetch record where receiver_id = 4 but i am always getting null output.

请参阅我的表格屏幕截图-

See my table Screenshot-

上面的屏幕快照有3行.第二行和第三行与其他ID一起存在4,我需要将其爆炸并显示第二行和第三行记录.

Above screenshot there are 3rows. second and third rows exist 4 along with other ids i need to explode that and show the second and third record.

如何编写MySQL查询?

How to write MySQL query?

推荐答案

存储逗号分隔的值确实是一个错误的设计,您应该 normalize ,首先将所有接收方关联存储在联结表中,如果您无法更改架构,则可以针对当前情况使用

Storing comma separated values is really a bad design you should normalize it first by storing all association of receiver in a junction table,If you are not able to alter your schema then for your current situation you can use find_in_set() to search values in a comma separated list

select * from table 
where find_in_set(4,receiver_id ) >0

这篇关于如何从数据库列中爆炸用户ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆