views:

24

answers:

2

I have a query returning 24 records for users with code A and 54 records for users with code B

and sometimes it will return Users with code C, D....etc there can be a total of 15 different Codes.

I want my query to only display the codes once, instead of returning retpeat users.

If i do something like

Select Count(user_code) from tbl_test and group by user_code

I will only get 54 and 24

if i do something like

Select Count(user_code) as number, user_code from tbl_test and group by user_code

I will get 54 B 24 A

I only want to return B A

is there any way i can do that or should i just use my second query?

+3  A: 

I may well have misunderstood big time here, but is this what you're after?

SELECT DISTINCT user_code FROM tbl_test

which is the same as:

SELECT user_code FROM tbl_test GROUP BY user_code
AdaTheDev
Perfect....That is what i was Looking for Thanks
WingMan20-10
The Distinct worked for me
WingMan20-10
+1  A: 

I'm not sure what you want exactly, but take your queyr and add a WHERE if you only want A and B included:

Select 
    Count(user_code) as number, user_code 
    from tbl_test 
    WHERE user_code in ('A','B')       ---<<--to only get counts for A and B
    group by user_code
KM