如何在MySQL中使用LIKE?
我有一个名为 music 的表,其中包含一些 id:
6983887641 59088763306 116542622632 106436032725763 6750402929 131572223581891 17337462361 56848544614 108089415891178 27659711968 182011613865 8888384363 43780515976 7872609449 38858586087 107901192572009 9028468518 5461947317 11955325695 64075031411 12673567174
我需要对这些 id 进行查询。如果执行了这样的查询:
SELECT username FROM music WHERE music LIKE '%107901192572009 9028468518%'
它将返回音乐表中具有这些 id 的用户的用户名。好的。但问题是如果我以不同的顺序添加 id 则没有结果。所以如果我搜索:
56848544614 107901192572009 or 5461947317 9028468518
它们在表中,但不按顺序,并且没有结果。我应该怎么办?
I got a table called music with some ids:
6983887641 59088763306 116542622632 106436032725763 6750402929 131572223581891 17337462361 56848544614 108089415891178 27659711968 182011613865 8888384363 43780515976 7872609449 38858586087 107901192572009 9028468518 5461947317 11955325695 64075031411 12673567174
And i need to do a query on those ids. If a query like this had been done:
SELECT username FROM music WHERE music LIKE '%107901192572009 9028468518%'
It would return with the username of the one that has these ids in it's music table. Ok. but the problem is if i add ids in different order there is no result. so if i searched for:
56848544614 107901192572009 or 5461947317 9028468518
They are in the table, but not in the order, and there is no result. What should i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,它会很慢。另请注意,它可能会失败,因为
id
可以是另一个id
的一部分。有一个更好的方法可以做到这一点 - 查找 1 对 n 关系。如果没有,至少考虑这样做(解决第二个问题):Note that it will be slow. Also note that it can misfire, since an
id
can be a part of anotherid
. There is a better way to do this - look up 1-to-n relations. If not, at least consider doing this (to combat the second problem):我认为你不想要像你想要的那样
I think you do not want LIKE you want IN