Link to home
Start Free TrialLog in
Avatar of Ann K
Ann K

asked on

In or Between

How to select all rows from the STUDENTS table where the ID number is any number from 100-500? Do I use in or between
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
IN Clause will expensive for this kind of query.. Pls use one of the option below-

Option1....

SELECT * FROM STUDENTS 
WHERE ID BETWEEN 100 AND 500

Open in new window


Option2....

SELECT * FROM STUDENTS 
WHERE ID>= 100 AND ID<=500

Open in new window


Option3.... Generate Number and join like below
SELECT DISTINCT s.*
FROM Master..Spt_Values v INNER JOIN STUDENTS s
ON s.ID = v.number
WHERE Number > 0 AND Number <= 500

Open in new window


Hope it helps !!