每当我运行它时,我都希望从查询中获得不同的记录。但有些记录返回两次或更多。逻辑必须如何解决,以便在此查询的每个循环中随机获取一条记录?
//Looping starts here
SELECT * FROM(
SELECT *,ims_2012_modifiye.id AS imsID, ims_2012_modifiye.ilac_id AS ilacID, ims_2012_modifiye.ilac_adi_duzgun AS iaDuzgun
FROM ims_2012_modifiye
LEFT JOIN ilaclar ON ims_2012_modifiye.ilac_id=ilaclar.id WHERE ims_2012_modifiye.ilac_id NOTNULL AND ims_2012_modifiye.pk_2013_1qrt<1 AND ims_2012_modifiye.asil_listede_mi=1 AND ims_2012_modifiye.ilac_id
NOT IN(SELECT ilac_id FROM piyasa_kontrol WHERE pk_yil IN (2010,2011,2012)) OR ims_2012_modifiye.oncelik_verilsin_mi=1
LIMIT 10
)ORDER BY random() LIMIT 0,1
//Updating pk_2013_1qrt to 1 here
//Looping Ends here
此外,我在每次查询后更新pk_2013_1qrt
字段以1
确保不会得到相同的结果。