Skip to content

Tag: greatest-n-per-group

Select all the last dates from all list of id

I’m trying to select all the videos that were last inserted, without repeating any ID_video_type (id_video_tipo column). Here’s an example of the data int the database: I’m trying to run the following query but when I do that I get the following result As you can see, I managed to get the vi…

SQL View Select Optional

I have a view that the current output something like this The rules are as follows Each group can only have 2 code and always have a default code vs not a default code. IF default code is not null, then always show the row. Regardless if Non default code has value or not If default code is null, then

get first row fo each group SQL

I have data like below. I would like to get the top choice for each gender from the following data I have tried mapping the choices by descending order as below : BUT, I would like to get the following table where i get the top choice for eachgender : Answer If you are runing MySQL 8.0, you can use

MySQL Group By for sorted table

I’ve two tables with these structures: Table 1 (comments) Table 2 (posts) My goal is to get a list with the latest comment from each post of a specific category_id. So for example, if I have category 1 as input I need the comments with the id 2 and 1 because these are always the last comments for each p…