dongzhi1851 2015-07-19 16:40
浏览 34
已采纳

SQL:3表内连接返回多个结果

SELECT video.name, video.description, video_source.url, bitcast_user.username
FROM video
INNER JOIN bitcast_user ON video.account_id = bitcast_user.id
INNER JOIN video_source ON video_source.video_id = {$_GET['id']};

This returns results with incorrect video names, descriptions and associated accounts but correct sources. There is a one-to-many relationship between users and videos, and videos and sources.

  • 写回答

1条回答 默认 最新

  • dsljpwi494719 2015-07-19 16:44
    关注

    You shouldn't do an INNER JOIN on a variable - that belongs in the WHERE clause. (Actually - I was even surprised that this worked at all.) I think you need a query like this:

    SELECT video.name, video.description, video_source.url, bitcast_user.username
      FROM video
      INNER JOIN bitcast_user ON video.account_id = bitcast_user.id
      INNER JOIN video_source ON video_source.video_id = video.video_id
      WHERE video_source.video_id = {$_GET['id']};
    

    (I'm not sure about video_source.video_id = video.video_id because I don't know how the column is named in the video table.)

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

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂