每当我运行它时,我希望从查询中获得不同的记录。但有些记录返回了两次或更多。逻辑必须如何解决才能在此查询中每个循环随机获得一条记录?
//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
,以确保不会获得相同的结果。
答案 0 :(得分:0)
您可以尝试
希望它有所帮助!