Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • I am not quite forced to use the design, so I can change it. It is mostly that the tables truly do contain vastly different columns and thus different data. The way they "belong" together is more that I deem them all important enough to want to know as a user when they have been updated. A view is a great idea though! I am aware of them and used them before, just never with Django's ORM, which is why I initially dismissed that idea. A quick google search told me though that views can be connected to Django's ORM so the fact I didn't think of that is entirely on me. Thanks for the answer! Commented Aug 14, 2021 at 13:21
  • Doesn't even need a view, just needs a SELECT query that performs the union across all tables, and then ORDER BY with a LIMIT. This will be efficient if the involved tables have an index on the update datetime column. Commented Aug 14, 2021 at 13:23
  • @amon That is true, Hans' approach does have 2 advantages though: 1) I can leverage Django's ORM with it, as Django models can be connected to view-tables (which I hadn't been aware of before). 2) If I have multiple occurrences for this kind of query I save myself the hassle in the future. Commented Aug 14, 2021 at 13:25
  • have you any data on how performant it is to use top and union? I would assume that it would need to retrieve more records than required and then trim off the extra, but maybe sql optimises that away Commented Aug 14, 2021 at 13:46
  • I think that given appropriate indexes could yield acceptable performance, as the SQL engine can probably do a merge sort based on the indexed datetime fields. Commented Aug 14, 2021 at 14:12