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

  • SEARCH
  • Home
  • 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 6694805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:08:41+00:00 2026-05-26T06:08:41+00:00

SELECT buttonID, live, title, image, (SELECT COUNT(*) FROM otherdb.buttonclicks t2 WHERE t2.buttonid = t1.buttonID

  • 0
SELECT 
  buttonID,
  live,
  title,
  image,
  (SELECT COUNT(*) 
    FROM otherdb.buttonclicks t2 
    WHERE t2.buttonid = t1.buttonID AND t2.`type`=0) as count 
FROM buttons t1
GROUP BY buttonID
ORDER BY live DESC, buttonID ASC;

We have 78 ad buttons on our site and have separated the stats from the main db for size reasons. We record every time one of the buttons is clicked on and I am working on a stats screen that can pull the information quickly.

The above query works but takes 4000 seconds (literally) to run, how can I get the same results much more efficiently.

Running the query as:

SELECT
  buttons.buttonID,
  buttons.live,
  buttons.title, 
  buttons.image, 
  count(buttonclicks.id) as count
FROM buttons INNER JOIN otherdb.buttonclicks ON buttons.buttonID = buttonclicks.buttonid
WHERE buttonclicks.type=0
GROUP BY buttons.buttonID
ORDER BY buttons.live DESC, buttons.buttonID ASC

is quicker but only picks up those buttons that have been clicked in the past three months (we archive the older clicks) because of the WHERE clause.

Solutions?

  • 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-26T06:08:42+00:00Added an answer on May 26, 2026 at 6:08 am

    try this query.

    SELECT tbl1.buttonID,
           tbl1.live,
           tbl1.title, 
           tbl1.image, 
           COUNT(tbl2.buttonid) as count
      FROM buttons AS tbl1
     INNER JOIN (SELECT buttonid FROM otherdb.buttonclicks b WHERE b.type=0) tbl2
        ON tbl1.buttonID = tbl2.buttonid
     GROUP BY tbl1.buttonID
     ORDER BY tbl1.live DESC, tbl1.buttonID ASC
    

    I also observed that you have an image field. I think the query slow because of this since it’s a blob type that handles an image object.

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

Sidebar

Related Questions

SELECT `name` , COUNT(*) AS `count` FROM `t1`, `t2` WHERE `t2`.`id` = `t1`.`id` GROUP
SELECT NR_DZIALU, COUNT (NR_DZIALU) AS LICZ_PRAC_DZIALU FROM PRACOWNICY GROUP BY NR_DZIALU HAVING NR_DZIALU =
SELECT User, COUNT(User) as count FROM Tests GROUP by User; This works. However, if
SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY hrl.Frn) as Row, hrl.unq, hrl.LcnsId, hc.Business,hc.Name,hc.Phone,
Select user_name [User Name], first_name [First Name], last_name [Last Name] From tab_user ORDER BY
SELECT items.item_id, items.category_id, items.title, items.description, items.quality, items.type, items.status, items.price, items.posted, items.modified, zip_code.state_prefix, zip_code.city, books.isbn13,
SELECT COUNT(id), AgeRange FROM ( select id, case when age < 0 then 'less
SELECT COUNT(*) FROM area WHERE ROUND(SQRT(POWER(('71' - coords_x), 2) + POWER(('97' - coords_y), 2)))
SELECT COUNT(*) AS test FROM %s WHERE id = %d AND tmp_mail <> ''
SELECT username, (SUM(rating)/count(*)) as TheAverage, count(*) as TheCount FROM ratings WHERE month ='Aug' AND

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.