I have a table having 200K rows. When I execute a query it's taking too much time; approximately 2 minutes.
This is my query:
SELECT a,b,c,d,@row:="tag1" as tag
FROM tableName
WHERE tagName like "%helloworld|%"
ORDER BY viewCount desc
LIMIT 20;
helloworld|
occurred only in 2 rows.
I want to change the query so if the data is present more than 20 times, it should return 20 rows else whatever rows present.
How to optimize this query?