I'm doing a query over 1 million customers in SQL. Can this query be further optimized?
I'm trying to optimize the search criteria.
In the WHERE
-clause:
SELECT *
FROM [TB_AGENDA-VENDEDOR_VENDEDORES] AS Vend
INNER JOIN [TB_AGENDA-VENDEDOR_CLIENTES] AS Cli
ON Cli.EQUIPE_VENDA = Vend.EQUIPE_VENDA
WHERE Vend.EMAiL = '[email protected]' ORDER BY PROXIMA_LIGACAO ASC, CATEGORIA ASC
And in the ON
-clause:
SELECT *
FROM [TB_AGENDA-VENDEDOR_VENDEDORES] AS Vend
INNER JOIN [TB_AGENDA-VENDEDOR_CLIENTES] AS Cli
ON Cli.EQUIPE_VENDA = Vend.EQUIPE_VENDA AND Vend.EMAiL = '[email protected]'
ORDER BY PROXIMA_LIGACAO ASC, CATEGORIA ASC
or if you have other ideas or reference?
Well due to the fact that both should be interpreted the same, there isn't a real difference between them.
I would personally suggest to add an index to your column Vend.EMAiL
. But only if your query runs more often than you add new rows to it. This really depends on the usage.
One example could be this index:
CREATE NONCLUSTERED INDEX NCI_TB_AGENDA_VENDEDOR_VENDEDORES_EMAIL
ON [TB_AGENDA-VENDEDOR_VENDEDORES] (EMAiL)
But as already said, it really depends on your usage and if you really want to retrieve all columns from both rows or only from one table or only some specific columns from each table.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments