DISTINCT RECORDS

  • Thread starter Thread starter thiago.ferrari
  • Start date Start date
T

thiago.ferrari

Hi! I have a query that displays the value "Descartados.Cod_animal" as
many times as "Sugestão.Cod_animal" matchs the conditions. What I want
is that the query shows me only one record per "Descartados.Cod_animal"
and discards the rest of records that matchs the conditions.

Example (NOW):
Descartados.Cod_animal | Sugestao.Cod_animal
6 2
6 8
6 5
7 2
7 8
7 5


Example (WHAT I WANT):
Example (NOW):
Descartados.Cod_animal | Sugestao.Cod_animal
6 2
7 8

Did I make myself clear?

Code:
SELECT Descartados.Cod_animal, Descartados.Tipo AS Descartados_Tipo,
Descartados.Sexo, Sugestao.Cod_animal AS Sugestao_Cod_animal,
Sugestao.Tipo AS Sugestao_Tipo, Sugestao.Sexo
FROM Sugestao, Descartados
WHERE (((Descartados.Tipo)=2 Or (Descartados.Tipo)=3) And
((Sugestao.Sexo)=Descartados.Sexo));
 
Dear Thiago:

The concept of keeping one and discarding all the rest is an "arbitrary"
thing. Other than the Cod_animal column, you are showing a number of other
columns of values. You must program the query exactly how to select the
values it will display. It will not arbitrarily remove all buth one of them
for you.

It is difficult to understand how you could want to display these additional
columns but yet not know or care which values will be shown. Perhaps there
is some underlying thingking about this that could clear up the problem.

Tom Ellison


Hi! I have a query that displays the value "Descartados.Cod_animal" as
many times as "Sugestão.Cod_animal" matchs the conditions. What I want
is that the query shows me only one record per "Descartados.Cod_animal"
and discards the rest of records that matchs the conditions.

Example (NOW):
Descartados.Cod_animal | Sugestao.Cod_animal
6 2
6 8
6 5
7 2
7 8
7 5


Example (WHAT I WANT):
Example (NOW):
Descartados.Cod_animal | Sugestao.Cod_animal
6 2
7 8

Did I make myself clear?

Code:
SELECT Descartados.Cod_animal, Descartados.Tipo AS Descartados_Tipo,
Descartados.Sexo, Sugestao.Cod_animal AS Sugestao_Cod_animal,
Sugestao.Tipo AS Sugestao_Tipo, Sugestao.Sexo
FROM Sugestao, Descartados
WHERE (((Descartados.Tipo)=2 Or (Descartados.Tipo)=3) And
((Sugestao.Sexo)=Descartados.Sexo));
 
Back
Top