Skip to content

Tag: mysql

SQL query for duplicate rows based on 2 columns

I have 3 tables movie, rating and reviewer movie has 4 columns movieID, title, year, director rating has 4 columns reviewerID, movieID, stars, ratingDate reviewer has 2 columns reviewerID, name How do I query reviewer who rated the same movie more than 1 time and gave it higher rating on the second review. Th…

updating data in a table from another table

I have two tables: cart_item product How to correctly update the data in the product table based on the data in the cart_item table? I want to update the quantity of products in the table product. By updating the data in product I will delete all products in the table cart_item. Here is what I would like to g…

Trying to utilize a window function instead of this script

I’m trying to improve my query for this topic at hand. I’m trying to find the top 5 and bottom 5 growth rates per state from 2020 to 2021 in my org. The table has the columns as specified: orderid, orderdate, totaldue, state, etc. (these are probably the most important columns). This is the query …

improve sql query with 2 EXISTS sub queries

I have this query (mysql): It runs multiple times on app start. It takes more than 10 seconds (all of them). I have indexes on: balance_histories table: budget_item_id, family_id (tried also payment_date) budget_lines table: family_id, budget_id, budget_item_id How can I improve the speed? Query or maybe mysq…