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 8517231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:38:28+00:00 2026-06-11T05:38:28+00:00

Ok, say I have a join query like this: SELECT users.* FROM users LEFT

  • 0

Ok, say I have a join query like this:

SELECT users.*
FROM users
LEFT JOIN votes ON (users.id = votes.userid)
GROUP BY users.id
HAVING count(votes.id) >= 0
ORDER BY count(votes.id) LIMIT 0,30

Which gets rows from users, sorted by the number of rows in the votes table with which they have a relationship.

My question: What is the proper way to use a WHERE clause like WHERE votes.timestamp BETWEEN date_add(NOW(),INTERVAL -24 HOUR) AND NOW(), such that users are sorted only based on the number of rows created in the past 24 hours with which they have relationships?

This makes sense to be able to do, I’m just not really sure where to put it.

  • 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-06-11T05:38:29+00:00Added an answer on June 11, 2026 at 5:38 am

    Add it to the ON clause:

    LEFT JOIN votes ON (users.id = votes.userid) AND (votes.timestamp BETWEEN date_add(NOW(),INTERVAL -24 HOUR) AND NOW())
    

    If you put the condition in the WHERE clause, you’ll potentially be eliminating the user completely, negating the purpose of the LEFT JOIN. The ON clause won’t have this problem.

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

Sidebar

Related Questions

Say I have the following: $query = SELECT user_id,email,password, roles.role_id,role_name FROM users JOIN roles
Let us say I have a query like this: SELECT * FROM ( SELECT
I have a query similar to the following: SELECT users.id FROM users LEFT JOIN
Say I have a query like this, where I join a number of virtual
If i have this Query: SELECT tableA.Id, tableB.Id FROM tableA JOIN tableB ON (tableA.bId
Say you have a query like SELECT t1.c1, t2.c2, ... more fields from joins
Let's say we have: SELECT * FROM Pictures JOIN Categories ON Categories.CategoryId = Pictures.CategoryId
Say I have a table like this: create table users ( user_id int not
My query works, and looks like this: SELECT SUM(`WTE`) / 1000 AS WTE FROM
This is query I have at the moment: SELECT `groups`.`id`, `groups`.`name`, `groups`.`description`, `groups`.`members`, `groups`.`image`,

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.