Select random with SQLServer (mssql)

3

What is the correct way to make an unspecified (random) selection using PHP + SQLServer, since Microsoft queries do not accept MYSQL's ORDER BY RAND ().

Using MYSQLI would look like this:

$sql ="SELECT * FROM Tabela where campo=‘algum'  order by rand()”;
    
asked by anonymous 15.01.2016 / 19:00

2 answers

3

According to this SO response , you can use ORDER BY NEWID() , which generates a uuid.

    
15.01.2016 / 19:11
0

It tries to load the random index before and assign it to the command string.

<?php

$indiceRandomico = rand(5, 15);

$sql ="SELECT * FROM Tabela where campo=‘algum'  order by ”. $indiceRandomico;

?>
    
15.01.2016 / 19:14