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.
- 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!Philipp Doerner– Philipp Doerner2021-08-14 13:21:02 +00:00Commented 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.amon– amon2021-08-14 13:23:27 +00:00Commented 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.Philipp Doerner– Philipp Doerner2021-08-14 13:25:52 +00:00Commented 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 awayEwan– Ewan2021-08-14 13:46:56 +00:00Commented 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.Hans-Martin Mosner– Hans-Martin Mosner2021-08-14 14:12:56 +00:00Commented Aug 14, 2021 at 14:12
Add a comment |
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
- create code fences with backticks ` or tildes ~ ```
like so
``` - add language identifier to highlight code ```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible) <https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you