Skip to content
Advertisement

How to get the last row in the table using group by with Order by DESC?

I have two tables, table one name (tbl_brands) with these columns:

enter image description here

and second table name (tbl_loader_attachment) with these columns:

enter image description here

I used this MySQL code below to sort by DESC:

When I execute my code select the first row appear (test1) I want to select the last row get (test4)

Advertisement

Answer

One approach uses a GROUP BY query:

If you are using MySQL 8+ (or should a future reader of this question be using MySQL 8+), then another option here is to use ROW_NUMBER:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement