distinct values of column

SELECT COUNT ( DISTINCT cust_code ) AS "Number of employees"
FROM orders;

checking above query at
https://www.w3resource.com/sql/aggregate-functions/count-with-distinct.php

how to display those unique values of  cust_code rather than just count
please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
Getting rid of the COUNT() will return unique cust_code's

SELECT DISTINCT cust_code
FROM orders;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
SELECT DISTINCT cust_code
FROM orders;
gave syntax error

SELECT DISTINCT (cust_code )
FROM orders;

above worked in microsoft sql
sql has to be same across all databases right why syntax differences?
_agx_Commented:
Shouldn't make a difference, but maybe remove the optional semi-colon?  Though it worked fine for me with SQL Server 2008, with or without the semi-colon.

CREATE TABLE #Orders ( Cust_Code varchar(50))  
INSERT INTO #Orders VALUES ('abc'), ('efg')

SELECT DISTINCT cust_code
FROM #orders;

Open in new window

Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

_agx_Commented:
sql has to be same across all databases

In this case the same syntax should work in just about any database. However, that isn't always possible. Some things in SQL are vendor specific.
Vitor MontalvãoMSSQL Senior EngineerCommented:
Something like this?
SELECT cust_code, COUNT(1) AS "Number of employees" 
FROM orders
GROUP BY cust_code;

Open in new window

Scott PletcherSenior DBACommented:
SELECT DISTINCT cust_code
FROM orders;
gave syntax error

No, it wouldn't: _agx_ gave you the syntax exactly correctly.

There is something else causing the error -- maybe a statement before it or after it??
gudii9Author Commented:
In this case the same syntax should work in just about any database. However, that isn't always possible. Some things in SQL are vendor specific.

is there link or resource where i can see which things are same which things are vendor specific across different databases?
_agx_Commented:
Unfortunately there are too many versions and operations to compile a complete list of differences.  Like the link below says, all of the db's I've ever used implement basic ANSI commands like SELECT/UPDATE/INSERT/DELETE, but other features differ depending on the vendor. Even when it's possible, it doesn't always behoove you to use generic ANSI SQL.  Sometimes Vendor A or B's implementation of a particular feature provides better performance than the generic version.  

Here are a few links to give you a general idea of some of the differences.  The ANSI version's a bit outdated, but gives the general jist..
https://dba.stackexchange.com/questions/1014/how-different-are-the-top-db-vendors-sql-dml-dialects-from-each-other
https://stackoverflow.com/questions/1714461/ansi-sql-manual#1714789
Geert GOracle dbaCommented:
Why does sql have to be the same for all db’s ?

There are inventions in companies, which are patented, and which will never be available in other db’s.
Take oracle’s locking for example
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.