Using EXISTS subqueries might be inefficient

Using EXISTS subqueries can be inefficient, the subquery executes for each and every row against the outer query’s table.

In the below example used on EXISTS subqueries which is non compliant way of writing SQL:


SELECT a.<<COLUMN NAME>>
FROM table1 a
where EXISTS (SELECT * FROM table2 b where a.column = b.column and b.column =<<Any value>> ) ;

A compliant solution would be like as below:


SELECT a.<<COLUMN NAME>>
FROM table1 a INNER JOIN table2 b
ON a.column = b.column and b.column =<<Any value>>;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s