Trucos SQL: Registro aleatorio en un select

Noviembre 30th, 2006 by kenavik

Para seleccionar una fila aleatoriamente de una tabla podemos usar la query:

select top 1 * from tabla order by newid()

De esta manera obtendremos un registro aleatorio cada vez que ejecutemos la query.

Posted in SQL SERVER |

2 Responses

  1. Marc Says:

    Mirate esto chavalote ;)

    Feliz navidad y que tengas un muy buen año!!!

    http://weblogs.sqlteam.com/jeffs/archive/2004/11/22/2927.aspx

  2. student Says:

    hola, gracias por este truco, es algo que necesitaba y me has facilitado la vida con esto, gracias y feliz navidad

Escribir un comentario

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.