Languages
[Edit]
EN

MySQL - SELECT query with GROUP BY and LIMIT

5 points
Created by:
Marcino
720

In this shot article, we would like to show how to solve the problem when we want to use SELECT query with GROUP BY and LIMIT in MySQL.

Quick steps:

  1. use nested query to number rows, e.g. article is here,
  2. then wrap the query using WHERE clause to find rows on proper page.

 Quick solution:

Where it is assumed:

  • page has 5 rows (d.`number` >= 10 AND d.`number` <= 15),
  • 3rd page is displayed (d.`number` >= 10).

 

Simple example

Edit

In this section, you can find query that finds number of hastags used with pagination.

 

Complex example

Edit

In this section, you can find query that finds number of hastags used by posts ordered by popularity with pagination:

 

See also

Edit
  1. MySQL - get row position with SELECT query

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join