doushi2902 2018-09-03 20:45
浏览 146
已采纳

MySQL - 如何在表中选择其中id值在另一个表的逗号分隔字段中的行?

I have been working on this problem for 3 days and am bleary eyed. I have an SQL "customers" table containing the customers name, address, email and a field called "venue" containing a comma delimited set of "id"'s of the venues of training courses they are interested in. (like: 18,22,35,41)

I have a second table called "venue" which holds the venues of all courses. Each course is a separate row in the "venue" table with an auto-increment id. The venue field in the "customers" table are a collection of the row "id" in the venue table which the customer selected at registration.

Once the customer is registered and is transported to the "my interests" page I would like to display the courses they have registered an interest in by outputting the row data of each "id" of the "venue" table that are held in the "customer.venue" field of the customer table.

I hope that makes sense...

My customer select

$sqlc = "Select * from customers ORDER BY id DESC LIMIT 1";

My venue selection

$venue = $result['venue'];

My current "venue" select code which isn't working

sqlcp = "SELECT * FROM venue WHERE FIND_IN_SET('$venue', id)";

Please ask any questions needed, thanks for looking

  • 写回答

2条回答 默认 最新

  • duanmei1850 2018-09-03 21:15
    关注

    I think you should write this code like :

    $sqlcp = "SELECT * FROM venue WHERE FIND_IN_SET(id,'$venue')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题