If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > return row where value is between column X and column Y

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-25-11, 04:56
wovin wovin is offline
Registered User
 
Join Date: Dec 2010
Posts: 7
return row where value is between column X and column Y

Hi all,

I have the following columns in my table

ID | minwidth | maxwidth
1 | 1 | 145
2 | 146 | 220
3 | 25 | 100
4 | 101 | 140
5 | 30 | 39


I want to perform a query where I can find the row where my php POST formvariable 'width' is dynamic.

Example:
If 'width' = 10 only row 1 should be returned
If 'width' = 180 only row 2 should be returned
If 'width' = 105 only row 4 should be returned etc. etc.

Thanks for the help!
Reply With Quote
  #2 (permalink)  
Old 01-25-11, 06:44
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
What SQL statements have you tried so far?
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
  #3 (permalink)  
Old 01-25-11, 07:26
wovin wovin is offline
Registered User
 
Join Date: Dec 2010
Posts: 7
I only know the BETWEEN statement as a possible solution but that just works with one column and 2 (dynamic) values. At least, that's what I think now...

SELECT * FROM table WHERE minwidth BETWEEN formvariable_X AND formvariable_Y

I would like something as

SELECT * FROM table WHERE formvariable_X BETWEEN column_X AND column_Y
Reply With Quote
  #4 (permalink)  
Old 01-25-11, 07:32
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by wovin View Post
I would like something as

SELECT * FROM table WHERE formvariable_X BETWEEN column_X AND column_Y
what happened when you tested this on your table?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 01-25-11, 07:46
wovin wovin is offline
Registered User
 
Join Date: Dec 2010
Posts: 7
Thumbs up

Sometimes I feel really stupid...It works like a charm, probably made a typo error causing the errors...Thanks for bringing me back to life

Anyway solution is:

SELECT * FROM table WHERE formvariable BETWEEN column_x AND column_y

Last edited by wovin; 01-25-11 at 07:59. Reason: solution
Reply With Quote
  #6 (permalink)  
Old 01-25-11, 08:52
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 623
Sometimes the solutions stare you in the face. Good job!!
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Tags
between multiple columns

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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