DEV Community

FatimaAlam1234
FatimaAlam1234

Posted on

SQL - Query Optimization

Rewriting Queries

SELECT * 
FROM Customers 
WHERE state = 'New York' AND city = 'New York';
Enter fullscreen mode Exit fullscreen mode

is equivalent to

SELECT * 
FROM Customers 
WHERE state = 'New York' 
AND city IN (SELECT city 
              FROM Customers 
              WHERE city = 'New York');
Enter fullscreen mode Exit fullscreen mode

Choosing the right index

CREATE INDEX index_name
ON table_name (column1, column2, ...);
Enter fullscreen mode Exit fullscreen mode

Fine-tuning Database Design

Changes such as the separation of specific data to different tables (Normalization), combining redundant data (Denormalization), or changing the way how tables are linked (Optimized Join Operations), can be implemented to optimize the schema.

Use of SQL Clauses wisely

SELECT column1, column2
FROM table_name
WHERE condition
LIMIT 10;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)