dsgoj7457 2013-09-29 02:57
浏览 22
已采纳

mySQL加入表没有重复[关闭]

I have two tables: One table contains poetry submitted by members. The other is the member's table. Both tables contain The Member's ID (MID and SubMID). I want to display the last 15 poems that have been updated. However, I want to display ONLY one work for any one author.

This works but it if an author updates a few works then they get displayed many times:

SELECT * FROM submits, members
WHERE submits.SubMID = members.MID AND submits.sub_approved = 'T'
ORDER BY submits.sub_Last_Update DESC LIMIT 15

You can see the results of that query here in the rolling marquee on the right: http://www.Prose-n-Poetry.com

The problem is that one author can take over the marquee by updating a few poems.

  • 写回答

2条回答 默认 最新

  • donglei3370 2013-09-29 03:11
    关注
    SELECT *
    FROM members m
    JOIN (SELECT s.*
          FROM submits s
          JOIN (SELECT SubMID, MAX(sub_Last_Update) lastUD
                FROM submits
                WHERE approved = 'T'
                GROUP BY SubMID) l
          ON s.SubMID = l.SubMID AND s.sub_Last_Update = l.lastUD) s
    ON m.MID = s.SubMID
    ORDER BY s.sub_Last_Update DESC
    LIMIT 15
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题