I would think you want to AND the ranges, not OR them:
WHERE (price BETWEEN lowprice AND highprice)
AND (sqft BETWEEN lowsqft AND hisqft)
Main Topics
Browse All TopicsI have a realator database that searches prices, SF, title, Address, etc and lists current listings with title, price, SF, etc.
Title: Building 1
Price: 100,000
Square Foot: 5,000 SF
Currently if one does a search between 90,000 and 200,000 building 1 should come up.
What one of our clients has suggested is that we have the ability to have a price range for the price. So for example
Title: Building 2
Price: 100,000 - 500,000
Square Foot: 5,000 SF
This is not a problem to list but to search, how does one go about this?
example If I searched between 200,000 and 400,000 the listing building 2 should come up. How do you write a SQL statement that captures this
SELECT * From Table WHERE Colum BETWEEN number range AND number range 2
So My question is how can I search between 2 number ranges. and is that the best way to go.
Example of current site http://www.youredc.com/htm
(if your are fimiliar with loopnet.com, they do this functionality)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks fro the response however if the listing has two colums Price1 and Price2 and is listed like below
title building 2
Price: 100,000 - 500,000 (which is colums Price1 and Price2)
Square Foot: 1,000
and I did a search from 200,000 to 300,000 (inputed into two text boxes searchprice1 and searchprice2)
SELECT * From Table WHERE (Price1 BETWEEN searchprice1 AND searchprice2) or
Price2 BETWEEN searchprice1 and searchprice2
this would not work because, searchprice1 and searchprice2 will miss Price1 and would miss Price2
Price1 100,000 does not fall in between 200,000 - 300,000
Price2 500,000 does not fall in between 200,000 - 300,000
think it is close to what you are looking for, just a slight variation on what drives the select...
SELECT * From Table
WHERE (searchprice2 >= Price1 and searchprice1 <= price2)
ie if searchprice 2 is greater than or equal to price1 and searchprice1 is less than or equal to price2 ie:
p1=100,p2=500,s1=200,s2=30
p1=400,p2=500,s1=200,s2=30
p1=400,p2=500,s1=300,s2=60
think it will give you what you are after - including overlapping ranges.
Business Accounts
Answer for Membership
by: chapmandewPosted on 2008-07-11 at 12:15:52ID: 21985158
SELECT * From Table WHERE (Colum BETWEEN number range AND number range 2) or
column2 between numberrange3 and numberrange4