Thanks - this is something you helped out with in the past.
The just was that there are tables storing information about lodges, and also tour operators. Both lodges and tour operators can have multiple keywords associated with them which are stored in separate related tables. And by using the count function its working so that we can show which tour operators are the best matches for each lodge based on how many keywords are associated with both the lodge and the tour operator.
The problem here is that the site owner has asked for a report listing lodges, and two different values from their keywords. So ‘Accommodation Type’ and ‘Country’ are keyword categories, and could have keyword including ‘Tented Camp (>20 tents)’ or ‘Tented Camp (<20 tents)’ for Accommodation Type, or ‘Kenya’ or ‘Tanzania’ for Country.
So the objective here is to show a list of all Tented Camps (>20 tents), which also shows the Country each is in.
So actually the value ‘Tented Camps (> 20 tents)’ doesn’t need to appear in the list, so long as the list did just contain the lodges with that keyword value.
(Note that Activity is just what I historically had my keywords named, so in this example a country can be an Activity. It would probably be better renamed ‘Keyword’.)
I can have a query looking like:
SELECT lodges.LodgeID
, Lodge
, Activity
, Subscription
, subscription_end_date
, CategoryID
FROM lodges
INNER JOIN lodge_activities_it
ON lodges.LodgeID = lodge_activities_it.LodgeID
INNER JOIN lodge_activities
ON lodge_activities_it.ActivityID = lodge_activities.ActivityID
INNER JOIN lodge_activity_categories
ON lodge_activities.Category_ID = lodge_activity_categories.CategoryID
LEFT JOIN product_likes ON lodges.LodgeID = product_likes.LodgeIDPL
WHERE CategoryID = 15
GROUP BY LodgeID
Will show the country in the list (CategoryID 15 = ‘Countries’)
So the aim, if possible, is to have a query like this:
SELECT lodges.LodgeID
, Lodge
, Activity
, Subscription
, subscription_end_date
, CategoryID
FROM lodges
INNER JOIN lodge_activities_it
ON lodges.LodgeID = lodge_activities_it.LodgeID
INNER JOIN lodge_activities
ON lodge_activities_it.ActivityID = lodge_activities.ActivityID
INNER JOIN lodge_activity_categories
ON lodge_activities.Category_ID = lodge_activity_categories.CategoryID
LEFT JOIN product_likes ON lodges.LodgeID = product_likes.LodgeIDPL
WHERE lodge_activities.ActivityID = 92
GROUP BY LodgeID
Where lodge_activities.ActivityID 92 = ‘Tented Camp (< 20 tents)’ but also somehow includes the country (i.e. where CategoryID = 15).
Not sure if that helps any more - I’ve tried to explain it as best I can, but not sure if it amounts to anything more than my original more simplistic example.