Skip to content

Tag: mysql

Query with group by date

I’m working on the following user table, where role = 2 means the user is an instructor, and role = 3 means that the user is a student. My goal is to select the sum value of all instructors and students, grouped by date. The result should look like this: In this case, on 2020-07-01, I had 1 instructor a…

get records that last record binded with it have a specific value

I have this case where there is 2 tables: book for example and loan for example: I need to get all books id , where the last loan duration equals , so in this example it will be : [1,2] Answer One method uses aggregation: This checks that the last id for a given book matches the last id for

Doing a simple join on two tables

I have the following two tables: team: game: I am trying to attain this output: I can do a simple join to receive one of the team names, but how do I get both names in one query? Answer Try this: You just need to join with the table “team” twice.

Using top N in sql

statement 1 statement 2 I have tried the above but both are not working. Does anybody know the reason? Answer If you want to update one row, then you can use limit: That said, I would expect id to be unique, so no LIMIT is necessary.