I know just enough SQL to get by, and lately, I'm not getting by so well!
I have a listing of records on my Web site that displays the total number of views each has received, along with last month's views, and this month's views. I'm currently running 3 separate queries, and using the recordcount from each to show the number of views.
Although this is working, it's grossly inefficient, and slowing things down. I know there's got to be a better way to do this. Is there a way to retrieve all 3 values with a single query?
TIA
I have a listing of records on my Web site that displays the total number of views each has received, along with last month's views, and this month's views. I'm currently running 3 separate queries, and using the recordcount from each to show the number of views.
Code:
<!--Total Views-->
SELECT *
FROM Table
WHERE ID = 'thisID'
<!--This Month-->
SELECT *
FROM Table
WHERE Month(DateViewed) = Month(GetDate()) AND
year(FirstEntered) = year(getdate()) AND ID = 'thisID'
<!--Last Month-->
SELECT *
FROM Table
WHERE year(DateViewed) = year(dateadd(m, -1, getdate()))
and month(DateViewed) = month(dateadd(m, -1, getdate())) AND ID = 'thisID'
Although this is working, it's grossly inefficient, and slowing things down. I know there's got to be a better way to do this. Is there a way to retrieve all 3 values with a single query?
TIA