Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

Database

Posted by Pankil Patel on March 31, 2010

During fetching record for referential integrity.

Instead of using “IN”  query use inner join / Cartesian product or Cross join, it will be very much faster than “IN” query.

Example:

IN Query:

select * from employee e where e.userId in (select u.userId from user u where u.status = “A”)

Inner Join Query:

select * from employee e inner join User u on u.userId = e.userId and u.status = “A”

Cartesian product or Cross join:

select * from employee e, User u where e.userId = u.userId and u.status = “A”

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

 
%d bloggers like this: