Skip to content

Tag: sql

UPDATE with RETURNING: Not able to retrieve ResultSet

I’ve tested the following UPDATE-RETURNING statement in my PostgreSQL client, and it correctly updates and returns the updated rows. However, in Java, I’m not able to retrieve the ResultSet. statement.execute() and statement.getMoreResults() always return false and statement.getResultSet() returns null, alway…

Join mysql table with distinct value from another table

I encountered a problem on a database I am working with. I have a table of counsels which may hold repeating values, but their is an enrolment number filed which is unique and can be used to fetch them. However, I want to join from a cases_counsel table on the “first” unique value of the counsel t…

Why are Duplicates not being filtered out

I am working on some practice interview Questions and am struggling with this: You are working with a company that sells goods to customers, and they’d like to keep track of the unique items each customer has bought. The database is composed of two tables: Customers and Orders. The two table schemas are…

Postgresql: join readonly database with csv-file

The task is to join data from local cdv-file with data from remote database. On this database I have readonly writes. So I can’t create new tables in this db. Only recommended way (which I have found) to do this is to: 1. Create new table in db 2. Copy (import) content of csv-file in this new table. 3. …

Excluding overlapped period in doctrine QueryBuilder

I have Product and Booking entity and I’m trying to select products that aren’t already booked in a given period. In other words, to select available products during a given period. To make myself understandable, see the schema below. I only want to select product that have a booking like #1 or #5…

Iterating multiple times over same table (postgres sql)

i am working with sql from few days as beginner and stuck at a problem! Problem: Given A table user_email_table which columns are (id, user_id, user_id_email) How to get all user co-related to each and every user extending himself user_email_table Desired Output Please Ignore validate data of email fields Thi…

Group by Latest value

I only want to show the latest value. Here is the table: InstanceID InstanceDate TotalProjects 1 2021-10-14 69 1 2021-10-12 70 2 2021-10-14 20 3 2021-10-14 89 3 ​ 2021-10-13 99 3 2021-10-11 100 4 ​ 2021-10-12 12 4 2021-10-14 13 5 ​ 2021-10-14 0 Here is the query I used to get this table: This is what I want:…