I’m trying to get a user’s total visits number for each web URL page that is stored in my database.
Bellow is my SQL query that will show total unique users where URL contains that keyword.
SELECT COUNT(DISTINCT userId) as someUrlTitleTotalVisitors
FROM someTable
WHERE urlCol LIKE '%someUrlKeyword%'
Now I have 50+ more pages to go, example:
SELECT COUNT(DISTINCT userId) as anotherUrlTitleTotalVisitors
FROM someTable
WHERE urlCol LIKE '%anotherUrlKeyword%'
.etc..
I would assume that I don’t need to write 50+ separate queries for each URL title, and I should be able to get all data with one call.
So, my question is how can I combine this query as one?
Ok, if you don’t have those keywords that you want to check on a table, then sadly, you are looking on a query like this:
Now, if you could put those keywords on a table, your query would be like this:
quite a difference, right?, and you could add or remove keywords on that table without touching your query, very handy.