Avoid Distinct

Avoid Distinct

Avoid Distinct :
We are using distinct in some queries to get required result set.
for instance,
SELECT DISTINCT(a.order_id) FROM order a, order_date d where a.order_id=d.order_id.
Here,
We are using order_date table in where clause.we are getting result set then pull out duplicates. It makes some delay.To optimize this query,we can use sub query .

SELECT a.order_id FROM order where a.order_id in (SELECT d.order_id from order_date d)

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.