473,378 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

help with multiple order by conditions...with rand()

3
hello, i tried searching for something similar to my situation but i haven't found so far..

for example ...
i have users table with 15 registered users and i want to show only 5 of them in front page...the table has (id) as unique value...
and i want to make an sql query that shows the 5 users registered lately...

...how?
by picking (random 5 ) users from the ( last 10 inserted users in table...) !!
this means the older ones won't show up...


so how i do this??

i thought of:
Expand|Select|Wrap|Line Numbers
  1. SELECT  * FROM  table WHERE id IN ( SELECT id FROM table ORDER BY id DESC LIMIT 10 )  ORDER BY  RAND() LIMIT 5 ;

but it gives errors...
any ideas?


(
note:
i do not want to use dates to collect the last 10 or something closer (since there might be days none registered)...

also i do not want to use MAX() to find last added id value then subtract 10...to find the last 10...
)
Nov 17 '07 #1
3 2877
mwasif
802 Expert 512MB
What about this one?
Expand|Select|Wrap|Line Numbers
  1. SELECT  * FROM  (
  2.     SELECT * FROM table ORDER BY id DESC LIMIT 10 
  3.     )  temp 
  4. ORDER BY  RAND() LIMIT 5 ;
Nov 18 '07 #2
dinox
3
What about this one?
Expand|Select|Wrap|Line Numbers
  1. SELECT  * FROM  (
  2.     SELECT * FROM table ORDER BY id DESC LIMIT 10 
  3.     )  temp 
  4. ORDER BY  RAND() LIMIT 5 ;
hey this is worked perfectly!!
thanks alot dude!! you are a great help!

i tried something exactly similar to this long ago but i got errors (i guess my bad) so i thought this is not the right way to begin with.... but in fact it is !
Nov 18 '07 #3
mwasif
802 Expert 512MB
You are welcome, glad to help you.
Nov 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mcp6453 | last post by:
I am trying to use Jack's FormMail script (http://www.dtheatre.com/scripts/formmail). Since I'm brand new at PHP and not very good at HTML, I have an easy question, which I will narrow down. When...
9
by: YZK | last post by:
Hello. I'm not a Web developer, just a user, and I think I may have somehow messed myself up majorly. I'm not quite sure how. Right now, javascript used by websites I go to either does not work at...
13
by: quickcur | last post by:
Suppose I have a function rand() that can generate one integer random number between 0 and 100. Suppose also rand() is very expensive. What is the fastest way to generate 10 different random number...
1
by: Jo | last post by:
I am having a real problem with the Launch conditions in VS .NET and can only come to the conclusion that it is a bug. It states quite emphatically in the MSDN that Launch Conditions WILL be...
21
by: dragoncoder | last post by:
Consider the following code. #include <stdio.h> int main() { int i =1; printf("%d ,%d ,%d\n",i,++i,i++); return 0; }
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
3
by: TamaThps | last post by:
I have to write a program that lets the user play the game of Craps. As of right now it is incomplete and I have run into some errors. It's my first time using functions instead of the program all...
18
by: luke noob | last post by:
can some one please help me adapt my script so that i can search for multiple words within my database, my keywords feild looks something like this.... Big Teddie Bear Collection Tiny Small...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.