stevember Posted December 27, 2010 Share Posted December 27, 2010 Hopefully I can explain this quite simply. In the database I have a number of places like: ID NAME 1 John 2 Mary 5 Nigel in its simplest form, the entries get added and removed regularly so therefore there will be gaps in the unique ID. I need to be able to select a random ID number. I cannot simply count them and pick a random number because it may not exist. I am sure there is a very simple way to do this, I guess I have eaten too much over Christmas to work it out. Link to comment Share on other sites More sharing options...
0 AnthonySterling Posted December 27, 2010 Share Posted December 27, 2010 SELECT id, name FROM table ORDER BY RAND() LIMIT 1; This can get fairly expensive on large data-sets though. ;) stevember 1 Share Link to comment Share on other sites More sharing options...
0 stevember Posted December 27, 2010 Author Share Posted December 27, 2010 SELECT id, name FROM table ORDER BY RAND() LIMIT 1; This can get fairly expensive on large data-sets though. ;) Brilliant, only ever 100 max so be perfect. Link to comment Share on other sites More sharing options...
Question
stevember
Hopefully I can explain this quite simply.
In the database I have a number of places like:
ID NAME
1 John
2 Mary
5 Nigel
in its simplest form, the entries get added and removed regularly so therefore there will be gaps in the unique ID.
I need to be able to select a random ID number.
I cannot simply count them and pick a random number because it may not exist.
I am sure there is a very simple way to do this, I guess I have eaten too much over Christmas to work it out.
Link to comment
Share on other sites
2 answers to this question
Recommended Posts