views:

55

answers:

2

I have tracking table tbl_track with id, session_id, created_date fields

I need count unique session_id for one day

here what i got:

select count(0) 
from (
       select distinct session_id
       from tbl_track 
       where created_date between getdate()-1 and getdate()
       group by session_id
)tbl

im feeling that it could be better solution for it

+5  A: 
select count(distinct session_id)
from tbl_track
where created_date between getdate()-1 and getdate()
nathan gonzalez
but here i will get many rows (count for each session_id), but what i need is one row with count of all unique session_id
msony
misunderstood the question. editing answer.
nathan gonzalez
+4  A: 

Why not just do exactly what you ask for?

   select count(distinct session_id)
   from tbl_track  
   where created_date between getdate()-1 and getdate()
Gabe
swear i didn't copy, though the formatting similarities are uncanny...
nathan gonzalez