Lista ofert - Tramping
select
offer.id
, offer.title
, offer.own_access
, offer.no_profit
, offer.promo_deal
, offer.best_deal
, offer_date.price_full
, offer_date.second_price
, offer_date.fly
, offer_date.currency
, offer_date.from
, offer_date.to
, offer.user_id
, offer.recommended_to
, offer.featured_to
, offer.participant_from
, offer.participant_to
, IF(offer.featured_to > UNIX_TIMESTAMP(), 1, 0) as featuredBool
, offer.type
, offer.location
, offer.custom_promo_title
from offer
left join offer_date on offer_date.offer_id = offer.id
left join offer_country on offer_country.offer_id = offer.`id`
left join country on offer_country.country_id = country.id
where 1 and offer.id in (select offer_id from offer_category where category_id = 75) and if(offer.on_request = 1, 1, (offer_date.from > 1550268826 or (offer.type = 2 and offer_date.to > 1550268826)))
and offer.status = 1
and offer.deleted != 1
group by offer.id
order by featuredBool desc, offer.on_request asc, offer_date.from asc
limit 0, 20