Re: Need help with a query
I adjusted the Select expressions to clarify what's going on. Your two Joins and your Where conditions impose overlapping logic--it's a belt-and-suspenders query, testing both market category IDs and names, producing skew. I think your requirement is met by a simpler query:
select
e.id, e.title, e.event_categories as cats, e.event_category_1 as cat1, e.event_category_2 as cat2, e.date_from,
c.id, c.category_name
from event as e
join event_category as c on c.id in(e.event_category_1, e.event_category_2)
where c.id=69 -- TEST CAT ID RATHER THAN NAME
and e.title like '%market%' -- IS THIS NECESSARY?
and left(e.date_from,7)='2017-07' -- FASTER THAN FUNC CALLS
order by date_from ;
+------+-----------------------------+------+------+------+------------+----+---------------+
| id | title | cats | cat1 | cat2 | date_from | id | category_name |
+------+-----------------------------+------+------+------+------------+----+---------------+
| 9316 | Summer Arts & Crafts Market | 0 | 50 | 69 | 2017-07-22 | 69 | Markets |
| 9478 | York River Art Market | 0 | 69 | 32 | 2017-07-29 | 69 | Markets |
+------+-----------------------------+------+------+------+------------+----+---------------+
Subject
Written By
Posted
Re: Need help with a query
August 02, 2017 11:27PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.