Skip to content

Case condition in hql

What I’m trying to achieve with this query is: always do the “mother” conditional, but if there isn’t mother, then do the “dad” conditional, is this posible? Answer This query: will try to join first by matching the column idMother to :idMother. If this is not possible then…

get records that last record binded with it have a specific value

I have this case where there is 2 tables: book for example and loan for example: I need to get all books id , where the last loan duration equals , so in this example it will be : [1,2] Answer One method uses aggregation: This checks that the last id for a given book matches the last id for

SQL Count: erratic behaviour

A piece of SQL that I have written is not behaving as intended. A vital piece of logic involves counting how many guests are VIPs, but the SQL seems to consistently get an incorrect answer. The …

How to edit and return a Cursor in plpgsql?

I am doing a simple query inside a function, and I need to change the values ​​of this query, but only for information. I don’t need to update the table as such. I managed to edit the values ​​but I don’t know how to return them. And below this function will be executed As you can see, the query d…

UNION does not remove duplicates in result

I have 2 queries that i need the result to be combined (no duplicates), i thought UNION would work but the result is as if i used UNION ALL. What i get now And what i want Answer You can try the below way – using aggregation on top of your query

Doing a simple join on two tables

I have the following two tables: team: game: I am trying to attain this output: I can do a simple join to receive one of the team names, but how do I get both names in one query? Answer Try this: You just need to join with the table “team” twice.