Hai Truong IT
Hai Truong IT

Reputation: 4187

How to using command sql get random 10 rows in php

I using sql in php, but, result not show:

test(id, name, type, category_id);

and my sql is:

select top 10( id, name) from test order by NewId()

How tio fix it

Upvotes: 0

Views: 94

Answers (4)

Ariful Islam
Ariful Islam

Reputation: 7675

SELECT 
     id, 
     name 
FROM test 
ORDER BY RAND() 
LIMIT 0,10

Upvotes: 0

Minras
Minras

Reputation: 4346

select top 10( id, name) from test
ORDER BY RAND()

Upvotes: 0

Alex Pliutau
Alex Pliutau

Reputation: 21957

Example from this post:

SELECT * FROM `table_name` ORDER BY RAND() LIMIT 10;

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

SELECT * from test ORDER BY RAND() LIMIT 10

Hope it helps

Upvotes: 0

Related Questions