MySQL - selecting entries with SELECT query

Associate
Joined
8 Apr 2004
Posts
2,053
Hi all, my MySQL knowledge is a bit rusty so I was wondering whether someone could help me with this. I would like to know how to write a SELECT query in 2 different ways:

1. if it returns a non-empty, it will select the first entry from the results
2. as above but it will return a random entry from the results (if it returns only 1 query, then it just selects the first since it is random; but if there are multiple entries, then select a random one)

This is because I'm planning to implement first a greedy, and then a randomized algorithm in my program.

Many thanks
 
Back
Top Bottom