Skip to content

Tag: sql

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…

Get data from same row with MAX()?

[MariaDB 10.4, PHP8.0] How can I rewrite this so it works so it get weight_date from the row with MAX(total_weight) and list it AS highest_weight_date? I have read that we can’t use MAX() among with WHERE? I have tested to rewrite several examples, but I give up and embarrassed show my latest try: I try…

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…

Getting sql data based on row value

I have a table like so: I’m trying to get the last date when the account was active, not counting today. If the id is not present on today’s date, it is not included in the final table. So for the case of id 1, that would be 2022-04-02, and for id 2, it would be 2022-04-01 I can do