1
how to use the GROUP BY
along with the ORDER BY
? need to order my tabela
so ASC
but I can’t use GROUP BY
how should I use the two together?
code snippet:
mysqli_query($conn, "SELECT nome_fotos, img, id_cliente FROM alboom WHERE id_fot = '$getid' GROUP BY id_cliente ORDER BY id ASC");
this and my code but it does not order the photos.
the result after the Workbench consultation was
nome_fotos = merry
img = merry.jpg
id_cliente = 2
that is it has not ordered because I have id = 1 in the database.
Which error appears?
– MarceloBoni
not error it just does not show the image in the order I want
– klaw
When you group information, you are hiding everything that repeats, however, you will not be able to "see" other information from these grouped records, i.e., you can no longer have fields in the
select
that in hisgroup by
. It won’t work. Aorder by
also makes no sense inside an undercurrent. If you do not want to show the repeats, use thedistinct
and to order use the correct field. Check that yourWHERE
is not limiting to only one (1) record your query not differentiating in ASC and DESC.– Ismael
What is the point of using the GROUP BY clause without an aggregation function? I don’t know if it was just a typo but you sort by this id field that doesn’t appear anywhere else in the SELECT command.
– anonimo
why use
group by
if the id_client does not repeat itself?– Ivan Ferrer