Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2010
    Posts
    7

    Unanswered: 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!

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    What SQL statements have you tried so far?
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    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

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    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?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    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 08:59. Reason: solution

  6. #6
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Sometimes the solutions stare you in the face. Good job!!
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •