lowest price from same field

Discussion in 'MySQL' started by bugcoder, Feb 19, 2009.

  1. #1
    hi all im a new bie. want to know that can we get the minimum value of same record. For example i have a row with a jewellery name "Celtic Ring" and it has different prices of e.g 10karat 18Karat and 24karat

    id = 1
    name = celtic ring
    price10k = 10
    price18k = 15
    price24k = 19
    price30k = 0
    price40k = 0


    how can i get the lowest price from this field and also it shouldn be zero?

    is it possible only with mysql without any php code
     
    bugcoder, Feb 19, 2009 IP
  2. chisara

    chisara Peon

    Messages:
    141
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You want the minimal value per column that would be 5 results per product, or would you like the minimum price for the product, that would be one value ?
     
    chisara, Feb 19, 2009 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    It would take a stored procedure to be able to return the lowest column of a single row. Databases aren't designed handle data storage and retrieval like this in a decent manner. If you want to do something like this the easiest way is to use 2 tables.

    table_1:
    id
    name

    table_prices:
    price_id
    item_id
    description
    price

    You can then add as many price / description combinations to a single item as you want and search, and retrieval becomes very fast and easy.
     
    jestep, Feb 19, 2009 IP