0
DISTINCT Query with multiple fields.
Hello! When I need to do a query with multiple fields (columns) and there are repeated records in all columns, how can I return a SELECT based on only one repeated field with DISTINCT (if it's possible...)??
4 Respostas
+ 1
maybe "GROUP BY %your fieldname%" will help u
+ 1
I did the following:
SELECT cad.ID, cad.Name, cad.Status, pe.Date FROM Register cad
LEFT JOIN Office pe ON cad.ID = pe.ID
WHERE cad.ID <= 100
GROUP BY cad.ID, cad.Name, cad.Status, pe.Date
...But, it keeps sending me back cad.ID repeated...
...The Query returns 103 rows, but I want only 100 (it starts from 1)
0
I did like this and worked:
SELECT cad.ID, max(cad.Name), max(cad.Status), max(pe.Date) FROM Register cad
LEFT JOIN Office pe ON cad.ID = pe.ID
WHERE cad.ID <= 100
group by cad.ID
...The field cad.Date have only 5 registers, so if I write a RIGHT JOIN it gives to me only 5 rows...
If anyone know a better way to do this..
- 1
try LIKE operator