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…
Select max value for each company in list, display longest value per company per day
I’ve looked at some of the other questions similar to this, but nothing I’ve found can quite get me there. I have a table with multiple columns, but 3 of the columns are Company, Date, and WaitTime. I want to select the longest WaitTime for each company and for each day. I’d like to display …
Update column values with dynamically created JSON MySql
I have a Relationships table that looks something like this And 2 tables From and To I’m trying to update the JsonPair column with Json objects in the form {FromName: ToName}. So the resulting table would look like I’m a novice at SQL. I’m thinking that I should SELECT the names first, then …
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…
is “SELECT fieldname, fieldName FROM MY_TABLE;” ever valid for any SQL database?
Do any SQL databases have case-sensitive naming for field names? What I mean is, in Java you can have two variables … Are there any SQL databases support that so … … would return two different columns? I’m asking because I’m building a database utility that has to work for MySQL,…
Oracle SQL – ORA-00936: missing expression
whats wrong about this code ? I am trying to display all data on Employee_ID & Salary column, nothing else. what am I doing wrong here ? Answer Is this what you want?
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
Select first and nth order for each client
I’m trying to display first and fifth order_id for each user. Table looks like this: I wrote something like this: But I want to see clients who made their first orders but don’t have fifths. There should be NULL, but I can’t understand how to make it. :c Answer Put the where t2.rn = 5 condit…
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…
How can I use an SQL query’s result for the WHERE clause of another query?
Okay, basically I have a table that contains statements like: I would like to use the contents from this table to generate other tables that fulfill the conditions expressed in this one. So I would need to make it something like But the last part of the where has to come from the first table. Right now what I…