SQL - How to list only records that have more than one daughter table

Asked

Viewed 23 times

0

I need to list the names of employees who have two or more children (are listed twice or more) in the following select, but have no idea how.

select f.NomeFunc as "Funcionário", d.NomeDep as "Filhos"
from Funcionario f
inner join Dependente d
on f.ID_Func = d.ID_func

Any hint?

  • Use the GROUP BY / COUNT clause along with the HAVING clause. By the way, it seems to me that you mistakenly used the expression "daughter table" in your question.

1 answer

0

To get this result, as commented, you need to first do a grouping and then use HAVING to filter the results. Your query would look like this:

select f.NomeFunc as "Funcionário"
from Funcionario f
inner join Dependente d
on f.ID_Func = d.ID_func
GROUP BY f.NomeFunc
HAVING COUNT(*) > 1

Browser other questions tagged

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