Query bringing duplicate items + product code

Asked

Viewed 374 times

0

Hi, I’m performing an SQL query on my Firebird server. I made the query using the following syntax:

select ds_produto_servico, count(ds_produto_servico) from tb_produto_servico
group by ds_produto_servico
having
count(ds_produto_servico) > 1

In other words, he is taking all the descriptions of the products that are duplicated. However, I would like to bring on the screen the code of these duplicated products. It is possible ?

The code field is: CD_PRODUTO_SERVICO

Thanks.

2 answers

2


Use the check query as subquery to bring the results:

select CD_PRODUTO_SERVICO, ds_produto_servico
from tb_produto_servico
where ds_produto_servico IN (
    select ds_produto_servico from tb_produto_servico
    group by ds_produto_servico
    having
    count(ds_produto_servico) > 1
)

0

select codigo_produto_servico from tb_produto_servico where ds_produto_servico in ( select ds_produto_servico from tb_produto_servico group by ds_produto_servico having count(ds_produto_servico) > 1 )

  • It didn’t work. He only brought the codes and not the descriptions.

  • In this case, just add the ds_producto_servico field in select, as in Rafael’s reply. In fact, our reply was practically identical, I only sent because I had not seen his reply (we sent at the same time).

Browser other questions tagged

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