sql.filterGymsCount = SELECT COUNT(*) FROM gyms g JOIN gymTypes gt ON g.id = gt.id_gym JOIN types t ON gt.id_type = t.id WHERE t.name IN (?) GROUP BY g.id HAVING COUNT(DISTINCT t.name) = ?
At the first question mark (IN clause) user can pass the type of the gym in order to filter them. This is comma seperated values for example:
B4X:
'Crossfit','HYROX'
At b4a, If I pass a single filter e.g. Crossfit without apostrophe, command working well. If I add apostrophe then does not return any value.
If I pass two filters without apostrophe then does not work.
I can't really understand where the problem stands.
If I test it at DBeaver as a sql script by adding two filters with apostrophe: 'Crossfit','HYROX' everything working fine.
You will need 2 question marks inside the bracket after the IN.
B4X:
sql.filterGymsCount = SELECT COUNT(*) FROM gyms g JOIN gymTypes gt ON g.id = gt.id_gym JOIN types t ON gt.id_type = t.id WHERE t.name IN (?, ?) GROUP BY g.id HAVING COUNT(DISTINCT t.name) = ?
You will need 2 question marks inside the bracket after the IN.
B4X:
sql.filterGymsCount = SELECT COUNT(*) FROM gyms g JOIN gymTypes gt ON g.id = gt.id_gym JOIN types t ON gt.id_type = t.id WHERE t.name IN (?, ?) GROUP BY g.id HAVING COUNT(DISTINCT t.name) = ?
Indeed, FIND_IN_SET helped a lot. Thank you for your answer.
Here is the code:
B4X:
SELECT COUNT(*)
FROM (
SELECT
g.id
FROM
gyms g
JOIN
gymTypes gt ON g.id = gt.id_gym
JOIN
types t ON gt.id_type = t.id
WHERE
FIND_IN_SET(t.name, 'Crossfit,HYROX,Yoga') > 0
GROUP BY
g.id
HAVING
COUNT(DISTINCT t.name) = 3
) AS subquery