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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀