Skip to content
Advertisement

Tag: database

Creating entity for database

For example, I have database with table book (id, title, themeId, authorId), table author (id, name) and table theme (id, name). I dont know, should i create entity exactly like in database (and then i will have problems with join queries): or create something like this: in second case i will have problems if authorId or themeId is null (it

Keyset pagination with WHERE & HAVING

I ran into a question that I can’t find a solution yet for keyset pagination: Suppose we have this query: How should we do keyset pagination on that? For a.number only, we can have WHERE a.number < ?; For rating only, we do HAVING rating < ?; If there’re two conditions for where, we can have WHERE (x, y) <

Sum unequal and removing duplicates from SQL query results

My base query: It can get me these outputs: Output example: Obs: There is a constraint on (id, on_date) meaning there can always be only one record of a project production on a specific date. Duplicate records, that have the same id, and exist in both dates and have different production values (wanted) Single records, that exists on only one

trying to select random data PostgreSQL

I’m trying to select random strings. The problem is it returns the same value for each row. Why is that and how to fix? 10 rows Answer Postgres overoptimizes the subquery. I think this is an error, because it is missing the fact that random() is volatile. A simple fix is a correlation clause: I rewrote the logic a bit,

List of values as table

I’m looking for a smarter way to have a list of values as a table in Oracle. What I do nowadays is select ‘value1’ as val from dual union select ‘value2’ from dual What I’m hoping for is some …

Advertisement