Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2009, 06:40 AM
krish_lr
Guest
 
Posts: n/a
Default Difference between IN and OR Command

hi all

what is the difference between "IN" and "OR" command in MS SQL?

Both give the same results.
 
Old April 16th, 2009, 10:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
what is the difference between "IN" and "OR" command in MS SQL?
For simple scalar expressions, nothing, though the IN clause is usually less typing. A WHERE clause like:
WHERE somecolumn = 1 OR somecolumn = 2
will result in a query plan that is identical to:
WHERE somecolumn IN (1,2)
Of course, the IN clause is really a 'set contains' operator, so you can construct expressions that are not really feasible with an OR operator, e.g:
WHERE somecolumn IN (SELECT acolumn FROM sometable)
__________________
-- Jeff
 
Old April 16th, 2009, 07:12 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

And the biggest difference, of course, is that IN can only be used with one field/column/test value.

OR is more flexible. IN is much more efficient in those situations where it can be used.





Similar Threads
Thread Thread Starter Forum Replies Last Post
command text was not set for the command objec needy Classic ASP Databases 1 April 8th, 2009 03:27 PM
Command text was not set for the command object Sheraz Khan Classic ASP Databases 2 May 29th, 2007 12:57 AM
connection.execute and command.execute difference vinod_yadav1919 Classic ASP Databases 0 September 28th, 2005 06:34 AM
Command text was not set for the command object. deepa12 BOOK: Beginning ASP 3.0 5 November 2nd, 2004 05:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.