Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5947883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:01:42+00:00 2026-05-22T17:01:42+00:00

I am doing a project where I am tracking users on a website, I

  • 0

I am doing a project where I am tracking users on a website, I log their every hit across the site. Whenever they hit a URL, I will create it in the database, and tag it with some tags.

Every URL is named a ‘resource’ in my database, and a resource can be tagged with multiple tags. A Visitor is connected to resources when they visit a URL, and when a user hits a resource, i also connect the date to it.

The thing I want to do is finding the resources with the correct tags, that has been watched this month or today for an example.

The query I am currently building is here:

SELECT r.resource_id, r.resource_url
FROM resource r
JOIN visitor_resource vt ON vt.resource_id = r.resource_id
JOIN resource_tags rt ON rt.resource_id = vt.resource_id
JOIN tags t ON t.tag_id = rt.tag_id AND t.tag_name =  '42'
GROUP BY r.resource_id

To give you an idea for the structure you can see here:
tracking database structure http://kaspergrubbe.dk/db-overview.png

So basically I will have to count how many visitor_resources there is in a given month by looking at visitor_resources.last_visited for the last month, and get the 5 most visited resources.

How to approach this?

The above query also seems very slow without query-caching, I suspect it is because t.tag_name is not an index, and that is a varchar, but is there anyway to speed up the process other than adding this index?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:01:43+00:00Added an answer on May 22, 2026 at 5:01 pm

    You’ve left out any criteria based on the date, so you should add that and see how the performance changes. Also, if you’re looking for a count then you should add that as well. I think that mySQL supports the LIMIT clause (as opposed to TOP), so add that for limiting it to the 5 most visited resources. With everything together it will probably look something like this:

    SELECT
        r.resource_id,
        r.resource_url,
        COUNT(*)
    FROM
        Visitor_Resources VR
    INNER JOIN Resources R ON R.resource_id = VR.resource_id
    INNER JOIN Resource_Tags RT ON RT.resource_id = R.resource_id
    INNER JOIN Tags T ON
        T.tag_id = RT.tag_id AND
        T.tag_name = '42'
    WHERE
        VR.last_visited BETWEEN <start of month> AND <end of month>
    GROUP BY
        r.resource_id,
        r.resource_url
    ORDER BY
        COUNT(*) DESC
    LIMIT 5
    

    Sorry, I don’t do a lot of mySQL these days, so I don’t know what the start and end date parameters would look like in the last line.

    Unless your Tags table is very large an index probably won’t matter much. An index on the Visitor_Resources.last_visited might be a good idea though.

    Also, I changed your table names in the query to be more consistent. Personally I like plural names, but singular are ok too. No matter which you choose though, pick one and stick to it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a project called user initiated real time object tracking system .
I am doing a project in ftp,which will do multiple uploads,and the process i
I am doing a project on criminal tracking using gps and i am not
I am doing a project which will finally print a pdf file or doc
Im currently doing research towards my final year BSc project. The final product will
Currently I am doing a GPS Tracking project based on Django and GREENTEL It
I am doing project euler question 33 and have divised a refactor to solve
After doing a project with WPF and getting very much attached to it's excellent
Im doing a project with C# winforms. This project is composed by: alt text
Im doing this project where i need to download files through a webservice (images,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.