Count diferent values (1 Viewer)

jcachado

New member
Local time
Today, 08:38
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:38
Joined
Feb 19, 2013
Messages
16,619
what does 'don't work' mean? No answer?, wrong answer? Something else?

Have you used the 'find duplicates' query wizard
 

plog

Banishment Pending
Local time
Today, 10:38
Joined
May 11, 2011
Messages
11,648
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

Top Bottom