Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?

by Anonymous Monk
on Jan 04, 2004 at 09:00 UTC ( [id://318638]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?
in thread Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?

SELECT ques_id FROM questions q, categories c WHERE q.category_id = c.category_id AND category = 'Mathematics' AND subject in ('Calculus', 'Geometry', 'Algebra') ORDER BY RAND() LIMIT 1
  • Comment on Re: Re: Re: Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Re: Is there a good way of retrieving entries randomly from a database (MySQL perhaps)?
by soon_j (Scribe) on Jan 04, 2004 at 09:10 UTC
    Just re-writing it, with a bit of correction (not a syntax type):

    SELECT ques_id
    FROM questions q, categories c
    WHERE q.category_id = c.category_id
    AND subject = 'Mathematics'
    AND category in ('Calculus', 'Geometry', 'Algebra')
    ORDER BY RAND()
    LIMIT 1

    The above query is for the subject 'Mathematics' only. How about for the other subjects? I am try to avoid repeating the above query for the next subject like Astronomy perhaps. I am try to consolidate all these tiny queries for each subject into a single and systematic query.

    Thanks! Jay

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://318638]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found