0

I feel like my question is extremely basic and has been answered before but I just can't seem to find anything about it.

Let's say I have a column named 'Names' and another called 'Level'.

-----------------------
 Names   |   Level
-----------------------
Scooby   |     3
Daphne   |     1
Shaggy   |     2
Fred     |     3
Velma    |     2
Scrappy  |     0

Basically I need a random name from the 'Names' column where 'Level' = 2. In this case randomly Shaggy or Velma. In reality the database will probably be in the dozens if not hundreds of the same 'Level' value.

I've seen code using:

SELECT column FROM table
ORDER BY RAND()
LIMIT 1

And I've tried playing with WHERE in there but with no success. Any ideas? Using PHP to fetch the data from MySQL to return to a Flash file. I apologize for the simplicity of the question.

0

2 Answers 2

3
SELECT Names FROM table1
where Level = 2
ORDER BY RAND()
LIMIT 1

SQL Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

@smcjones: your comment makes no sense. This SQL works because that's the way it is written.
0

Have you tried this?

SELECT `Names` FROM `table_name`
WHERE `level` = 2
ORDER BY RAND()
LIMIT 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.