WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-29-2005, 03:08 PM
richkoi's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Columbus, Ohio
Posts: 487
richkoi RepRank 0
Default Database Field - Range (mySQL)

I would like to know the best way to set up a database so a query can easily search for a range of data. For example, my current mySQL database is as follows:



Using this table I would like to create a query for a plant that would be between 30-40 feet. This would display only the Bambusa oldhamii plant.

1) Is there a better way to set up the database for this? If so, how? Also, what would the query be?

2) Using the existing format, what would be the best way to query this for a range? Is it even possible?

Please let me know if you need clarification.

Thanks,

Rich
Reply With Quote
  #2 (permalink)  
Old 06-30-2005, 12:24 AM
brian.mark's Avatar
Administrator
 

Join Date: Jul 2004
Location: Omaha
Posts: 2,717
brian.mark RepRank 2brian.mark RepRank 2
Default

Code:
select * from planttable where (Ht_Min >= 30 and Ht_Min <= 40) OR (Ht_Max >= 30 and Ht_Min <= 30);
I think that should do what you were asking. Ranges, especially when 2 variables are involved, can get confusing.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #3 (permalink)  
Old 06-30-2005, 01:05 PM
richkoi's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Columbus, Ohio
Posts: 487
richkoi RepRank 0
Default

Thanks, I'll try that query out.

Rich
Reply With Quote
  #4 (permalink)  
Old 06-30-2005, 04:05 PM
richkoi's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Columbus, Ohio
Posts: 487
richkoi RepRank 0
Default

Here is another suggestion I got:

Quote:
Rich
I think I have a query that will catch all the possibilities.

The inputs are X=Low Y=High

SELECT * FROM plant_table WHERE (Ht_max BETWEEN X AND Y) OR (Ht_min BETWEEN X AND Y) OR (Ht_min <= X AND Ht_max >= Y)

from the examples you would get
X Y
20 30 The first 'between' gets Oldhamii and the 2nd 'between' gets Aurea
25 60 Both 'between' statements get Oldhamii
35 50 The last 'AND' statement gets Oldhamii
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Tags: , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0