Query to add fields from two tables

Asked

Viewed 59 times

1

I need a query where I will need to add people by color and race, distinctly, for example, make the sum not only by name, but also by color and race alike. I tried something below, but it’s adding up only the same names.

select COUNT(*), pessoas.nome, qualidades.cor, qualidades.raça                                  
from pessoas, qualidades where pessoas.id_qualidades_pess=qualidades.id_qualidades
group by pessoas.nome

Thank you,

  • 3

    Add the fields cor and raça at the GROUP BY and has its solution!

  • It worked!!!! Thank you

2 answers

0

Grouping by the fields that are important to you, according to the query below where was added the field race and color in the grouping,

  select 
        COUNT(*), 
        pessoas.nome,
        qualidades.cor, 
        qualidades.raça                                  
    from pessoas, qualidades 
    where pessoas.id_qualidades_pess=qualidades.id_qualidades
    group by pessoas.nome
        qualidades.cor, 
        qualidades.raça   

0


Just leave only the required in the "group"

select COUNT(*), qualidades.cor, qualidades.raça                                  
from pessoas, qualidades 
where pessoas.id_qualidades_pess=qualidades.id_qualidades
group by qualidades.cor, qualidades.raça

 [Documentação][1]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.