table : kisiler
name surname points
----- -------- ----
ali elli 1
ali elli 5
ali elli 5
veli kollu 3
veli kollu 4
adem bacakli 2
ali elli 4
veli kollu 5

Q ; how can i get result has been showed below;

ali elli 15
veli kollu 12
adem bacakli 2

thanks

Dani AI

Generated

already has the right idea — you need to group the rows and then sort the groups by the summed value. 's suggestion to use GROUP BY is correct; to get the rows with the highest total points first, order by the aggregate (either the SUM() expression or an alias you give it).

Example (use an alias and sort by it):

SELECT name, surname, SUM(points) AS total_points
FROM kisiler
GROUP BY name, surname
ORDER BY total_points DESC;

If you want deterministic ordering when totals tie, add secondary keys (for example, highest single score or alphabetical name):

... ORDER BY total_points DESC, MAX(points) DESC, name ASC;

Dialect notes and quick tips:

  • MySQL: you can refer to the alias in ORDER BY and use LIMIT N to return the top N results.
  • MS Access: use SELECT TOP N ... to limit rows; Access supports aliases in ORDER BY too. If points can be NULL, use COALESCE/IFNULL in MySQL or Nz() in Access to treat NULL as zero before summing.
  • If you only need the single most popular person, use LIMIT 1 (MySQL) or TOP 1 (Access).

Further reading on grouping and aggregates:

  • MySQL reference on GROUP BY and aggregates:
  • MS Access aggregate functions reference:

Recommended Answers

All 2 Replies

yes it works but, i want to use order by points desc is well. i can do it. bigest point will be first row, lowest last.

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.