mysql去重,用DISTINCT,GROUP BY?

发布:2013-09-06 13:10   点击769次   评论:0
mysql去重,用DISTINCT,GROUP BY?

文章:news表, nid, mid, subject
会员:member表, mid, mname
要求:取会员最新发布的文章,会员发布多条,只取最新一条:

SELECT MAX(n.nid)AS nid, n.subject, m.mid, m.mname
FROM news n
INNER JOIN member m ON m.mid=n.mid 

GROUP BY n.mid ORDER BY MAX(n.nid) DESC LIMIT 10;



应用中更复杂点的:


SELECT a.ccid1,a.ccid13,a.subject,MAX(c.cid)AS cid,c.mid,c.oprice,c.createdate,m.company 
FROM cms_commu_offer c
INNER JOIN cms_members_2 m ON m.mid=c.mid 
INNER JOIN cms_archives12 a ON a.aid=c.aid 
GROUP BY c.mid ORDER BY MAX(c.cid) DESC LIMIT 10;

关于 GitHub 导航 部门 反馈

提示:`/home.php`入口数据仅为演示功能,不构成任何交易凭证,也不承担相关风险和责任!

Copyright © 2011-2018 xxxxx.com All rights reserved.

Run:2.872/30.227(ms); 7(sql)/2.876(MB); comm:news/detail; Upd:2025-01-11 07:56:11