Razlika DISTINCT i GROUP BY

Zašto izbacuju različite rezultate?

$sql_kopi=mysql_query(“SELECT DISTINCT dend, id_kat FROM brojevi_borbi WHERE id_dan=$prdan_k AND id_boriliste=$k”); - izbaci ok

																			$sql_kopi=mysql_query("SELECT dend, id_kat FROM brojevi_borbi WHERE id_dan=$prdan_k AND id_boriliste=$k GROUP BY dend"); - izbaci jednu vrijednost manje

a tablica je ista:

29 5
29 5
31 3
31 3
28 4
27 4
26 4
26 4
26 4

?

Da u doljnjem dodaš id_kat bilo bi isto

GROUP BY dend, id_kat

[quote=""]“group by” lets you use aggregate functions, like avg, max, min, sum, and count. “distinct” just removes duplicates.

For example, if you have a bunch of purchase records, and you want to know how much was spent by each department, you might do something like:

select department, sum(amount) from purchases group by department

This will give you one row per department, containing the department name and the sum of all of the “amount” values in all rows for that department.[/quote]


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Webmaster.Ninja