SELECT a.*, CONCAT_WS(":",, a.alias) AS `id`,v.street,, v.state,, v.title AS vtitle, AS `country_code`,cc.title as cctitle, AS `country`,CASE
							WHEN a.repeated != "" THEN evr.start
							ELSE a.start
						END AS evr_start,
							WHEN a.repeated != "" THEN evr.end
							ELSE a.end
						END AS evr_end,
						a.starttime AS evr_starttime,
						a.endtime AS evr_endtime,
							WHEN a.repeated != "" THEN
							ELSE 0
						END AS evr_id
FROM #__events_v5_events AS a
INNER JOIN #__events_v5_venues AS v ON a.venue_id =
INNER JOIN #__events_v5_categories AS cc ON a.category_id =
INNER JOIN #__events_v5_countries AS c ON c.code =
LEFT JOIN ( SELECT main_evd.event_id, main_evd.start,, main_evd.end FROM #__events_v5_repeating_days AS main_evd LEFT JOIN
							SELECT event_id, MAX(start) AS past_event_start
							FROM #__events_v5_repeating_days
							WHERE `start` < NOW()
							GROUP BY event_id
						) AS past_event ON main_evd.event_id = past_event.event_id LEFT JOIN
							SELECT event_id, MIN(start) AS future_event_start 
							FROM #__events_v5_repeating_days
							WHERE `start` >= NOW()
							GROUP BY event_id 
						) AS future_event ON main_evd.event_id = future_event.event_id WHERE (future_event.event_id IS NOT NULL AND main_evd.start = future_event.future_event_start)
						OR (future_event.event_id IS NULL AND main_evd.start = past_event.past_event_start)) AS evr ON = evr.event_id
WHERE (( IS NULL AND a.end >= NOW()) OR ( IS NOT NULL AND evr.end >= NOW())) AND a.published > 0 AND a.access IN (1,1) AND a.language in ('he-IL','*') AND cc.language in ('he-IL','*')
ORDER BY a.start 
   בחרו כמות להצגה