I am having the following query and I am wondering how should I construct an index for each of the clients and products tables.
Also, with all these Where, Inner join, Group by, Order by clauses, what order does a composite index apply to a query similar to the one above?
Code:
SELECT clients.id AS id, clients.name AS name, COUNT(DISTINCT products.product_id) AS counts FROM clients INNER JOIN products ON (clients.id = products.client_id) WHERE CAST("2008-07-30" AS DATE) BETWEEN products.start AND products.end AND products.flag=0 AND products.price<=products.value AND products.price<=clients.balance GROUP BY clients.id ORDER BY clients.name ASC LIMIT 0, 100
Comment