dqiatvbi61502 2012-04-09 08:25 采纳率: 0%
浏览 122
已采纳

从mySQL中的2个表中选择数据,加入它

I need to select data from 2 tables in my DB - comments and users. This is the structure of these tables:

comments:

commentID | commentDateAndTime | imageID | userID | comment

users:

userID | username

I need to select all the data in both tables, join it on userID, where imageID should be equal to $imageID. I tried the following SELECT statement:

    return json_encode(select("
    SELECT
     commentDateAndTime,
     imageID,
     userID,
     COMMENT,
     username
   FROM users
    JOIN comments
    ON comments.userID = users.userID
   WHERE comments.imageID = $imageID
   GROUP BY comments.comment   
"));

But I didn't receive any data.

Any advice, please?

  • 写回答

2条回答 默认 最新

  • dongshan2680 2012-04-09 08:39
    关注

    Why are you using group by if you need all the result.

    SELECT users.* , comments.*
    FROM users JOIN comments ON comments.userID = users.userID 
    WHERE comments.imageID = $imageID 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料