how to select random unique records on each execution of the SQL Query

前端 未结 2 1046
孤城傲影
孤城傲影 2020-12-21 16:25

I have a table \"masterurls\" it has morethan 1 million records. I want to fetch random records each time the query executed. It should not have any of the records that were

2条回答
  •  无人及你
    2020-12-21 16:49

    How are you going to know if the url is already accessed before. My best suggestion would be setting a flag to know this in the table. Add a field like view in the table which will accept two values 1 or 0, 1 for already accessed and 0 for not accessed. Then you could use

    SELECT m.url FROM masterurls m WHERE view='1' ORDER BY RAND() LIMIT 200;
    

提交回复
热议问题