I have this query that run on MS SQL Server:
SELECT o.phone AS Number, o.code AS Code, o.name AS Name,
o.expireDate AS ExpireDate, o.disabled AS cardStatus, a.disabled AS AccountStatus,
MAX(j.cDate) AS LastUse
FROM [DATAB].[dbo].[Card] AS o
LEFT OUTER JOIN [DATAB].[dbo].[journal] AS j
ON j.phone = o.phone,
[DATAB].[dbo].[CardType] AS ct, [DATAB].[dbo].[Account] AS a,
[DATAB].[dbo].[CardProduct] AS cp
WHERE o.accountProductId = ct.id
AND ct.accountId = a .id
AND a.number = 'XXXXXXXXXX'
AND ct.partnerProductId = cp.id
AND cp.code = 'XXXX'
GROUP BY o.phone, o.code, o.disabled, o.name, o.expireDate, a.disabled
ORDER BY o.name ASC;
I'd like to optimize it in order to run faster, but don't how to start.
FYI, I have checked the estimated execution plan, the index analyse of DATAB].[dbo].[journal] says that it cost 70% of the query, but there is no index issue message.
a.numberandcp.codealso.