Count diferent values

jcachado

New member
Local time
Yesterday, 16:41
Joined
Aug 5, 2015
Messages
4
Good Morning,
Help, I have a table where I have two columns: articles and bar_code.

I wanted a result that would tell me which articles have more than 1 bar code but only the different ones or +1.

Thank you for your help.
This code don't work:

SELECT artigo,
count(distinct codigo_de_barra) as [Mais de 1]
from tabela
group by artigo
having count(distinct codigo_de_barra) > 1

Thks,

JC
 
what does 'don't work' mean? No answer?, wrong answer? Something else?

Have you used the 'find duplicates' query wizard
 
Distinct doesn't work like that (https://www.w3schools.com/sql/sql_distinct.asp). It works in the SELECT and on everything in the SELECT. What you want is going to take a subquery:

Code:
SELECT articles, bar_code
FROM YourTableNameHere
GROUP BY articles, bar_code

That will generate all unique articles/bar_code permutations. Then you build the query you attempted with that to find articles with more than one bar code.
 

Users who are viewing this thread

Back
Top Bottom