views:

34

answers:

3

This is really dumb question but still my head cannot work it out. I have a table with Orders, each order has userID in it. User can have unlimited amount of Orders. How do i make count of unique userIDs ?

+8  A: 

You can;

SELECT COUNT(DISTINCT userID) 
FROM Tbl

You can give the count column a name by aliasing it:

SELECT COUNT(DISTINCT userID)  NumberOfDistinctUsers
FROM Tbl
Alex K.
Thanks, works.... placed DISTINCT before count and got wrong result...
eugeneK
+3  A: 
select count(*) from
(select distinct userid form ordertable) d
Pranay Rana
A: 

can you show the schema for your tables?

Iain