472,099 Members | 2,276 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Undefined rand expression ?

Hey guys, i don`t understand whats wrong with this sql statement....Any ideas ?

SELECT *
FROM Temp
ORDER BY rand();
Jul 24 '07 #1
13 2283
pbmods
5,821 Expert 4TB
Heya, redskycorp.

Nothing jumps out at me. Maybe enclosing your table name in backticks will help. Also, usually when you ORDER BY RAND(), you tend to also LIMIT:

Expand|Select|Wrap|Line Numbers
  1. SELECT
  2.         *
  3.     FROM
  4.         `Temp`
  5.     ORDER BY
  6.         RAND()
  7.     LIMIT 1;
  8.  
Jul 24 '07 #2
I did this....

SELECT *
FROM `Temp`
ORDER BY rand()
LIMIT 2;

Now it says syntax error (missing operator) in query expression ' ran() LIMIT 2 '....
Jul 24 '07 #3
dafodil
392 256MB
Try to put a where statement on it...

For example:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM `pdt_tracker` where `Track_ID`
  3. ORDER BY rand()
  4. LIMIT 2;
  5.  
  6.  
  7.  
Jul 24 '07 #4
Ok now it getting weird.....This is what i did...

SELECT *
FROM Temp
ORDER BY Rand;

Now it does randomize but it asks me to enter parameter, i don`t want the dialog box to pop-up....so i tried...

SELECT *
FROM Temp
ORDER BY Rand
LIMIT 3;

Now an syntax error missing operator in query expression 'Rand LIMIT 3' appears..... What am i doing wrong ?
Jul 24 '07 #5
dafodil
392 256MB
Ok now it getting weird.....This is what i did...

SELECT *
FROM `Temp`
ORDER BY Rand;


Now it does randomize but it asks me to enter parameter, i don`t want the dialog box to pop-up....so i tried...

SELECT *
FROM Temp
ORDER BY Rand
LIMIT 3;

Now an syntax error missing operator in query expression 'Rand LIMIT 3' appears..... What am i doing wrong ?
Just put this:
Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2. FROM `Temp`
  3. ORDER BY Rand();
  4.  
Instead of:

SELECT *
FROM Temp
ORDER BY Rand;


Put a () after Rand and dont forget this `` enclosing the Temp

Cheers
Jul 24 '07 #6
SELECT *
FROM `Temp`
ORDER BY Rand();

I did this but i get error undefined Rand in expression......how do i define Rand() ?
Jul 24 '07 #7
dafodil
392 256MB
SELECT *
FROM `Temp`
ORDER BY Rand();

I did this but i get error undefined Rand in expression......how do i define Rand() ?
It seems that the problem is in your sql... That's odd, its ok in my sql...
Maybe you are using an old version of mysql. Try updating it...
Jul 24 '07 #8
The thing is i am not using mysql. I am trying to write a query in access, designing query is done using sql codes......
Jul 24 '07 #9
dafodil
392 256MB
The thing is i am not using mysql. I am trying to write a query in access, designing query is done using sql codes......
I'm not sure but try to replace Rand() with Random() since there is a Random() function in access...
Jul 24 '07 #10
Eureka ! I finally found the solution ! Thanks dafodil, after trying out your codings and experimenting a bit, i got the answer.......

SELECT *
FROM Temp
ORDER BY Rnd(Len([Topic]));

It was just that simple, and here i was knocking my head trying to figure out the answer.....thanks again guys !
Jul 24 '07 #11
bartonc
6,596 Expert 4TB
Eureka ! I finally found the solution ! Thanks dafodil, after trying out your codings and experimenting a bit, i got the answer.......

SELECT *
FROM Temp
ORDER BY Rnd(Len([Topic]));

It was just that simple, and here i was knocking my head trying to figure out the answer.....thanks again guys !
Which would have been found much more quickly if you had posted in the relevant forum. Please try to keep your threads in the forum to which they belong (or at least put something like "In Access, how do I...?" so that a moderator can move your thread to where it belongs. Thanks.
Jul 24 '07 #12
Sorry bartonc, i thought since the question was more on sql, i thought this thread was more appropriate....sorry....
Jul 24 '07 #13
bartonc
6,596 Expert 4TB
Sorry bartonc, i thought since the question was more on sql, i thought this thread was more appropriate....sorry....
It's no problem. The thing is that MySQL is not generic SQL and I'd like to see you get answers to your questions in an efficient manner.

Thanks for the reply,
Barton
Jul 24 '07 #14

Post your reply

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

Similar topics

14 posts views Thread by ozbear | last post: by
3 posts views Thread by Mantorok Redgormor | last post: by
12 posts views Thread by RoSsIaCrIiLoIA | last post: by
49 posts views Thread by matty | last post: by
57 posts views Thread by fctk | last post: by
12 posts views Thread by Rajesh S R | last post: by
22 posts views Thread by blargg | last post: by
33 posts views Thread by coolguyaroundyou | last post: by
reply views Thread by leo001 | last post: by

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.