Hey guys, I am also working on the same project and I have tried numerous options for the query (UNION, mulitple SELECTs inside the FROM and a couple of JOINs).
Allow me to explain. I am not a really good SQL programmer or anything so please bare with us.
We are tracking page views inside a table:
Views
View_id (AI)
viewer_id (INT)
location_id (INT)
location_type (INT)
time (INT)(UNIX_TIMESTAMP)
the View_id is obv the unqiue key in this table. Tje viewer_id is the id of the user that viewed the page, or 0 for guests. the location id is the ID of the location displayed, but since we have several types of locations (say, 6 different types), I chose to store the type also instead of using 6 different tables. so the combination of location_id and location_type is important, thought (in this table) obviously not unique.
Regardless, the result we would want is(I am most familiar with php arrays so);
[0] =>(
[location_id] => 1,
[location_type] => 1,
[total_views] => 89,
[views_since_yesterday] => 60
),
[1] =>(
[location_id] => 1,
[location_type] => 3,
[total_views] => 140,
[views_since_yesterday] => 10
),
[2] =>(
[location_id] => 2,
[location_type] => 4,
[total_views] => 200,
[views_since_yesterday] => 9
)
I hope I am getting the point accross here. Its supposed to be something of a "Trending Locations" kind of thing.
I'm sorry for the confusion before!
@mikosiko - I have no idea what you just wrote... But thanks anyway!