dousou1878 2012-04-04 21:30
浏览 49
已采纳

Mysql逗号将列匹配与另一个表分开

I would like to select all matches from a commaseparated column in table2, where column could be like this: 0,1,2 OR 2,4,5 OR 2,5 OR 1,3,5 etc.

I have tried with:

SELECT * from table where 1,3,5 IN(SELECT commaseparated FROM table2) WHERE ..

But error on statement when using commas.

I've also tried using REGEXP but in my case i need to search for all matches within 1,3,5

How can i solve this one? :)

  • 写回答

1条回答 默认 最新

  • duanpao6163 2012-04-04 21:36
    关注

    Can't do that in standard SQL. it's

       WHERE singlevalue IN (list, of, values)
    

    if you want to compare lists against lists, you should revamp your tables so they're properly normalized. Storing formatted data in a field basically negates the purpose of having a relational database - you can't establish relationships with the data if it's not in a format that allows relationships to be formed.

    If those CSV lists were in sub-tables, you could do a very simple JOIN query to meet your specifications.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题