SELECT distinct `wp_cb_bonuses`.`id_bonus`, `bonus`.`post_title` nume, if(`wp_cb_casinos`.`prioritate` != -3,if(date(`wp_cb_bonuses`.`data_expirare`) >= now(),1,0),0) expirat, if(`wp_cb_casinos`.`prioritate` >= 0,0,-1) low_casino,`wp_cb_casinos`.`prioritate` prioritate_casino, `wp_cb_bonuses`.`post_ID` bonus_post_ID ,data_expirare,`bonus`.`post_date`, `wp_cb_bonuses`.`first_same_casino`,`wp_cb_casinos`.`post_ID` casino_post_ID,`wp_cb_casinos`.`post_review_ID` casino_post_review_ID, `bonus`.`post_modified`,`wp_cb_casinos`.`online`, 99 page_pos,`random`, `wp_cb_bonuses`.`prioritate` `prioritate`, `wp_cb_bonuses`.`ordine` `ordine`, `wp_cb_casinos`.`id_casino`,valid_for,`bonus`.`post_content`, `wp_cb_bonuses`.`id_casino`, `wp_cb_bonuses`.`maximum_cashout`, `wp_cb_bonuses`.`suma`,`wp_cb_bonuses`.`supralink`,`wp_cb_def_tip_bonuses`.`supralink` supralink_tip, `wp_cb_bonuses`.`minimum_depozit`, `wp_cb_casinos`.`maximum_cashout` maximum_cashout_casino, `wp_cb_bonuses`.`procent`,`wp_cb_casinos`.`force_monsterlink`, `wp_cb_casinos`.`minimum_depozit` minimum_depozit_casino,waggering,DATE_FORMAT(data_expirare, '%d/%m/%Y') data_expirare2,`bonus`.`post_modified_gmt`,DATE_FORMAT(post_modified_gmt,'%M %e, %Y') updated, `wp_cb_casinos`.`id_media_logo`,`wp_cb_bonuses`.`id_media`,rating,`wp_cb_bonuses`.`id_tip_bonus`, `wp_cb_bonuses`.`cod_bonus`,`wp_cb_def_tip_bonuses`.`post_ID` type_post_ID ,`wp_cb_def_tip_bonuses`.`nume` bonus FROM wp_cb_bonuses INNER JOIN `wp_cb_def_tip_bonuses` ON `wp_cb_def_tip_bonuses`.`id_tip_bonus`=`wp_cb_bonuses`.`id_tip_bonus` INNER JOIN wp_posts `bonus` on `wp_cb_bonuses`.`post_ID` = `bonus`.`ID` INNER JOIN `wp_cb_casinos` ON `wp_cb_casinos`.`id_casino`=`wp_cb_bonuses`.`id_casino` WHERE ( `wp_cb_bonuses`.`id_bonus`!= 913 and `wp_cb_bonuses`.`id_casino`=24 and (date(`data_expirare`) >= now())) AND `bonus`.`post_status` ='publish' and app_only = 0 order by expirat desc, page_pos asc, low_casino desc, first_same_casino DESC, case `wp_cb_bonuses`.`id_tip_bonus` when 2 THEN 1 when 1 then 2 When 6 then 3 When 3 then 4 When 16 then 5 When 9 then 6 When 10 then 7 else 8 end,`bonus`.`post_date`, `prioritate` desc ,`ordine` desc,`data_expirare`,`post_date` desc limit 0,5