Rukmi Patel
Rukmi Patel

Reputation: 2561

fetch random unique records from table

I want to fetch 50 random records without duplication.

Table Name : table 1
Fields : test_id,test_name,test_phone.

Can anyone suggests me query that can fetch 50 random records from database without duplication?

Upvotes: 0

Views: 124

Answers (3)

Ayman Safadi
Ayman Safadi

Reputation: 11552

Try:

SELECT DISTINCT * FROM table_1 ORDER BY RAND() LIMIT 50;

Do make sure that they're unique, make sure that test_id is an auto-increment INT.

Upvotes: 2

Zlatan
Zlatan

Reputation: 698

Try this

SELECT DISTINCT * FROM table ORDER BY RAND() LIMIT 50

Contact if you have any doubt.

Upvotes: -2

Manigandan Arjunan
Manigandan Arjunan

Reputation: 2265

use the following query

SELECT distinct * FROM `table_1` order by rand() limit 50

it works.

Upvotes: 1

Related Questions