mercredi 15 juin 2016

mysql random records give a duplicate data

I am developing a website where records are not sequential, records are displayed randomly. I use simple mysql random method to display random records by using rand() with limit where limit is parameterized to get next record one by one.

I am using asp.net mvc framework and mysql database.

Here is mysql query.

select distinct
lw.Lawyer_id,
lw.name,
StateName,
ct.city,
Date_of_registration,
lawyer_views,
fl.practice
from
    registration lw
        left join
    states st ON st.Id = lw.State_Id
        left join
    city ct ON ct.id = lw.City_Id
        left join
    total_views lwv ON lwv.l_id = lw.L_id
        left join
    rsuper rsub ON rsub.l_id = lw.L_Id
        left join
    lfilter fl ON fl.L_Id = lw.L_Id
where
    lw.City_Id = '577'
        and rsub.special_id = 1
        and lw.status = 'Active'
        and lw.L_id != 1
        and lw.service = 'Free'
order by rand()
limit start , pageSize

in this query pageSize is total number of record which is 18 and start variable is change according to parameter but default value is 0.

It gives 18 records randomly on ajax request but problem is that it gives some duplicate records.

please tell me how to prevent this or other better solution for it and i also try other alternatives of rand() function but it not helps me. I used this tutorial for better improvements in random records. http://ift.tt/1qcJP43

Aucun commentaire:

Enregistrer un commentaire