Mailinglisten-Archive |
----- Original Message ----- From: "Tobias Orterer" <der_(at)_Tobi.li> To: <mysql-de_(at)_lists.4t2.com> Sent: Friday, January 12, 2001 1:46 PM Subject: Random row SELECT der auf ggf. fehlende IDīs achtet > einem SELECT. Hab schon limit rand(),1; ausprobiert weil das > "angeblich" gehen sollte, war aber nicht der fall... > Ok, ich war etwas voreilig und habe Dein Posting nicht zuende gelesen. Also schnell mal http://www.mysql.com/doc/M/a/Mathematical_functions.html besucht. --------------------------------------------- RAND(N) Returns a random floating-point value in the range 0 to 1.0. If an integer argument N is specified, it is used as the seed value: mysql> select RAND(); -> 0.5925 mysql> select RAND(20); -> 0.1811 mysql> select RAND(20); -> 0.1811 mysql> select RAND(); -> 0.2079 mysql> select RAND(); -> 0.7888 You can't use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times. In MySQL Version 3.23, you can, however, do: SELECT * FROM table_name ORDER BY RAND() This is useful to get a random sample of a set SELECT * FROM table1,table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000. Note that a RAND() in a WHERE clause will be re-evaluated every time the WHERE is executed. ----------------------------------------------- Dann müßte ja eigentlich folgendes gehen: select irgendwas from tabelle order by rand() limit 1 Gruß, Jens Peter Möller --- *** Weitere Infos zur Mailingliste und MySQL unter http://www.4t2.com/mysql
php::bar PHP Wiki - Listenarchive