Skip to content

Accessing array elements in query postgres

I’m currently building a query to retrieve some data from my db, I need to access the documents stored in an array, this is how the table crm_company looks: I have another table for users by document crm_user which looks like this: What I want as a final result is: I just have tried somehing like the fo…

Django get objects that are foreign key of two models

I have the following three models where Budget and Sale both contain a foreign key to Customer: I want to get a queryset of all Customer objects for which both a Budget and Sale exists. I initially tried getting the intersection of the customer field of all Budget and Sale objects: This returns the correct ob…

Two dimensional comparison in sql

DB schema There are rows with the same cryptid, I need to squash them to one row. So the cryptid becomes effectively unique. The complexity comes from the fact that I need to compare dates by rows as well as by columns. How to implement that? The rule I need to use is: status should be taken from the row

Why am I getting a duplicated column when doing this SQL query?

I am trying to do a set of queries in mySQL. In my final query I am trying to select the course_id column, but there are two columns with the title course_id and the exact same values, so I am encountering an error saying Query Error: Error: ER_NON_UNIQ_ERROR: Column ‘course_id’ in field list is a…