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…
Tag: sql
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…
SQL statement to increment multiple case functions from multiple tables
I’m trying to increment the SQL generated column “Counter” by making 1 case statement. I get the error “Invalid Column” for Counter in my case statement. Any help is appreciated. Answer Shot in the dark. It’s not clear what order you need the rows to be counted or what the …
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. …
Trying to count the number of occurences that 3 columns from 2 tables have on my organizations table? I need the occurrences joined in one table
org_id is the foreign key that reals both the users table and topics table. It keeps giving me the wrong result by only either counting the number of admins or standard users and putting that for all rows in the each column. Any help is really appreciated as I have been stuck on this for a while now! So, I
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…
Deadlock when we we have dependent entities in hibernate and try to update table using multiple threads in Vertica
I have two java classes. Father.java and Children.java I receive the Deadlock X exception if several threads visit the same table (entity father) to updates with distinct row entries, even though the records are different. Is there any way to fix why the entire table locks up instead than just one row? Even t…
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:…