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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:34:09+00:00 2026-05-30T06:34:09+00:00

I want to choose an entry from my database randomly, but not on every

  • 0

I want to choose an entry from my database randomly, but not on every call, but depending on some other external factor as the week of the year, or the day of the year. How Can I achieve this?

This will tell me the current week:

SELECT DATE_FORMAT(CURDATE(),'%u');

So, to get an entry based on this value, I choose the entry number:

SELECT (DATE_FORMAT(CURDATE(),'%u')+0) MOD (SELECT COUNT(*) 
FROM my_view 
ORDER BY id);

So, my attempt:

SELECT * FROM my_view
LIMIT (SELECT (SELECT DATE_FORMAT(CURDATE(),'%u')+0) MOD (SELECT COUNT(*) 
  FROM my_view
  ORDER BY id))
,1;

And all I get is this:

ERROR 1064 (42000): You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version 
for the right syntax to use near '(SELECT (SELECT DATE_FORMAT(
CURDATE(),'%u')+0) MOD (SELECT COUNT(*) FROM ' at line 1

Maybe this is not the best approach? Is this not possible?
Thank you.

UPDATE: I want to insert this on a VIEW, so I can only use SELECT statements. Anyways, I’ve already solved this, please see this comment: Weekly-based ORDER BY on MySQL

  • 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-30T06:34:10+00:00Added an answer on May 30, 2026 at 6:34 am

    The reason of the error you see is that LIMIT clause can take only literals as arguments, it doesn’t accept variables.

    If you want to select different (random) number of rows, you can create a function that accepts desired number of rows and in a loop select rows to the temporary table. After that you can just select everything from that table.

    If you want to choose an entry based on some data, then you should play with ORDER BY and select N first rows.

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

Sidebar

Related Questions

Similar question , but for Oracle. Why would I not always want to choose
I want to choose random numbers within a range of numbers, but with weighting
I've learned several languages, but now I want to choose one. The language that
I want the user to be able to choose from a dropdown Combobox listing
I have two tables USER and TRANSACTION i want to choose the data from
I want to choose an image formate for including images in both html and
I'm setting up a new project and I want to choose a license that
I have a vector/array of n elements. I want to choose m elements. The
I want to give my users the ability to choose how their public page
In order to choose categories, I want to use dropdown lists. Each list contains

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.