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条)

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题