开发者

What is the best way to do this SQL task?

What would be the best 开发者_如何学Goapproach with this SQL-based logic:

I need to get some groups from a table. However there are thousands of items, which can belong to only one of those groups (say one of the five/ten/fifteen groups returned). I can get the groups and then loop all of the item objects and insert them into the group.

Or would it be better to get all the objects which belong to a group, loop them, and insert them into the belonging group? What would be the difference in performance?


If you're just looking for the groups, then a simple SELECT DISTINCT group FROM Table will return those. If you want each of the rows and their associated groups, well a SELECT * (not for production use...) would get that as well. If you want them in order, then a SELECT with an ORDER BY group would do.

What are you going to do with this information?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜