English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

SELECT nameFROM users WHERE taken_flag = '0' AND new_flag = '0' AND cooling_off = '0' AND name_in_float = '0' ORDER BY rand() limit 1

There is too many ands in my query and it doesnt appear to work, how can I make it work?

2007-08-13 02:51:40 · 3 answers · asked by jeff lemon 1 in Computers & Internet Programming & Design

3 answers

SELECT name FROM users WHERE taken_flag=0 AND new_flag=0 AND cooling_off=0 AND name_in_float=0 ORDER BY rand() LIMIT 1

Unless you have these columns as a string equivalent (ie char, varchar, text...) don't put the values in '0', aslong as these are valid fields you can do a select with as many restraints as you want. And so you know this will only return 1 record since you put the LIMIT as 1

2007-08-13 03:00:12 · answer #1 · answered by Big D 4 · 0 0

The number of 'And's you're using shouldn't be an issue.
Try running the query with just the first And, and then add one at a time until you find which part of the statement is causing the error

2007-08-13 10:01:48 · answer #2 · answered by Dave 4 · 0 0

You have not read my previous answer on your question on random badge numbers.
There are not too many ANDs (no limit), but your "rand()" is wrong.
Correct your code as I explained to you, so you get a return on your errors, if any.
Your function is always returning the first record found in the table.
You DO NOT use "ORDER BY" when you put "LIMIT 1"!
Think about it!
"Get ONE record (LIMIT 1), SORT it (ORDER BY)!"
Where is your logic?

2007-08-13 14:11:27 · answer #3 · answered by just "JR" 7 · 0 1

fedest.com, questions and answers