Sasha
Sasha

Reputation: 20824

help optimize sql query

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

Upvotes: 0

Views: 128

Answers (2)

nathan gonzalez
nathan gonzalez

Reputation: 11987

select count(distinct session_id)
from tbl_track
where created_date between getdate()-1 and getdate()

Upvotes: 5

Gabe
Gabe

Reputation: 86698

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()

Upvotes: 5

Related Questions