I want to update table prod_replay_out based on subquery results in Postgres. However, subquery returns multiple rows but I want to skip those rows and update table based on single rows return by subquery. I have referred link Subquery returns more than 1 row error but max() function will not apply for my expected results. Could you please provide me
Tag: subquery
CTE Recursive Query to Grandparents
I have following table: What I need to get is SELECT query that will return only rows that have ISDELETED 0 and ISINEDIT 0 and whose parents or grandparents are 0 as well I currently have: But for some reason it returns double rows Answer You need to add the same isdeleted = 0 AND isinedit = 0 predicate to
MAX COUNT BY GROUP BY Retrieve only max count records
I want to return only the max count record from the following grouping. This Returns: Ideally it should return only : Sort the manufname asc by Tried this but returns the same: Answer You can use dense_rank or rank window function. Also I have removed unnecessary aggregation in the top query. You can use TOP with ties as following
SQL Query to group by month and display individual month sum for a record
I’m trying to sum product codes with a particular description as total products sold in a month over the years. The two table used are: The date format is in ‘DD-MON-YYYY HH12:MI PM’. So far I’m able to formulate this: How do I separate the count as different month columns and get the sum of count in a separate column?
Why this select selects no rows
I am trying to select a highest earner in ‘IT’ department, but I keep selecting no rows. Salary and names are in table called employees while department_name is in a table named departments. Can anyone please explain why does this select no rows and how should I do it? Answer Why this select selects no rows? Your query fails because
Oracle filtering with multiple Exists but only one can evaluate
Please consider this pseudo-query: Consider that: “From A” is much more complex and I don’t want to do more joins there. I’m filtering results and foreach record A i just want to return a single row, that’s why I have the exists in the order i want them to evaluate; How can I avoid running the 2nd exists (due to
MySQL Get Change From Cumulative Results in Consecutive Rows by Identifier
I am running MySQL Community Server version 8.0.19. I have been struggling with the following problem whilst working through publicly available COVID19 data. I am using a dataset that is both …
Convert this SQL into eloquent ORM
I want to convert the following sql statement into eloquent: I did this as like below: The problem is that it is converting to the same sql but showing error. The error is shown below: * order_number, order_id, sum(quantity) as qty, sum(price) as pr from orders right join order_details on orders.id = order_details.order_id group by order_number) * The tables are:
How can I get the 10 most recent rows from a database?
I want to choose an id in a table, sort it by date and show only the 10 newest entries. I have already tried following command: SELECT * FROM weather WHERE DATUM = (SELECT MAX(DATUM) WHERE ID=’0′)
Access SQL JOIN with subquery
Can someone tell me how I can convert this query to work in MS Access? SELECT Shooters.idShooters, Shooters.firstname, Shooters.lastname, JoinedContingent.Count, JoinedShots.Count FROM Shooters …