Skip to content
Advertisement

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

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

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:

Advertisement