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
Query that will select a timeframe from specific date to today
I’m having issues in my WHERE clause selecting data from a specific day to today’s date. The day/time format in my date column is ‘7/2/2020 3:12:08 PM’. I’ve tested a couple options but keep getting this error – ‘literal does not match format string’. Any idea&#…
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 …
What are best practices for login and passwords when there is only one user?
I feel like there’s a lot of information for developers on protecting user information when there are multiple users who each need to have their passwords stored. But what if there is only 1 user? A sign up page wouldn’t be needed as you could set the username and password yourself. I’m basi…
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…
SQL Server 2019 – archive remote DB daily with archive date in each table
I am very new to SQL and was hoping for some help. I have a database that is hosted remotely and I want to take a snapshot of all the views and archive them in a local 2019 database daily with an ‘archived’ date field in each of the local tables. So far I have managed to set up an
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.
How to use Group By with Task<IEnumerable> in LINQ
I am new to the entity framework and LINQ. Trying to learn it by example. I have an Entity called “Participant” as below: I am trying to use Group by and return the result as Task<IEnumerable<Participant>>. The Sql Query that I found the is : SELECT Count(Id) as #, Zip FROM [database].…