在 MySQL 中获取不同的 id
我有一个这样的表结构:
Comments table
id review_id user_id created comments deleted
1 10 28 2011-10-12 "hi" 0
2 11 28 2011-10-13 "yo" 0
3 10 28 2011-10-15 "bye" 0
我想从每个评论中获取按创建的 DESC 排序的最新评论。所以我有这样的东西:
SELECT DISTINCT review_id, 'comments' as type FROM comments as MyTable WHERE
user_id=28 AND deleted=0 ORDER BY created DESC LIMIT 30
所以在上表中我想要返回 id = 3 然后 id = 2 的行。
I have a table structure like this:
Comments table
id review_id user_id created comments deleted
1 10 28 2011-10-12 "hi" 0
2 11 28 2011-10-13 "yo" 0
3 10 28 2011-10-15 "bye" 0
I want to get the latest comment from each review sorted by created DESC. So I have something like this:
SELECT DISTINCT review_id, 'comments' as type FROM comments as MyTable WHERE
user_id=28 AND deleted=0 ORDER BY created DESC LIMIT 30
So in the above table I want the rows for id = 3 and then id = 2 returned.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
示例查询:
https://data.stackexchange.com /stackoverflow/s/2143/getting-distinct-ids-in-mysql
Example Query:
https://data.stackexchange.com/stackoverflow/s/2143/getting-distinct-ids-in-mysql
请将这段代码集成到您的代码中。
表数据:
运行查询:
结果:
Please integrate this code in your code.
Table data:
Run query:
Result: