Oh, that's hot! 

Thanks!
.......................
Ben Nadel 
Web Developer
Nylon Technology
350 7th Ave.
Suite 1005
New York, NY 10001
212.691.1134 x 14
212.691.3477 fax
www.nylontechnology.com

Sanders: Lightspeed too slow?
Helmet: Yes we'll have to go right to ludacris speed.
-----Original Message-----
From: Nick Han [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 11, 2006 6:01 PM
To: CF-Talk
Subject: RE: Distinct value count (SQL)

Ben,

  Do this, assuming you're using sql server.
  

        Select count(distinct user_id)
        From orders


-----Original Message-----
From: Ben Nadel [mailto:[EMAIL PROTECTED]
Sent: Tuesday, April 11, 2006 2:51 PM
To: CF-Talk
Subject: Distinct value count (SQL)

So, I have to do queries occassionally where I have to get the count of
unique items in a query. I don't want to return the items, I just want to
count them. I end up doing something like:

-----------------------------+
SELECT
        COUNT(*) AS user_count
FROM
        (
                SELECT DISTINCT 
                        o.user_id
                FROM
                        orders o
        ) AS t1 
-----------------------------+

I always hate doing it this way as it seems like an extra step that there
must be a way to avoid. And, I know zero about how SQL works behind the
scenes, but this just seems like it would need to create some temp table,
which may or may not be the best way. 

I tried to do the following, but id returns the count of each group, not of
the record set.

-----------------------------+
SELECT
        COUNT(*) AS user_count
FROM
        orders o
GROUP BY
        o.user_id
-----------------------------+

So, any suggestions? Or is this just a two part process??

Thanks,
.........................
Ben Nadel
Web Developer
Nylon Technology
350 7th Ave.
Suite 1005
New York, NY 10001
212.691.1134 x 14
212.691.3477 fax
www.nylontechnology.com

Sanders: Lightspeed too slow?
Helmet: Yes we'll have to go right to ludacris speed.






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:237487
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to