Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQL - Hide Prices where decimal fields are 0

Options
  • 22-06-2013 2:15pm
    #1
    Registered Users Posts: 763 ✭✭✭


    Guys....doing a favour for a friend and he needs a MySQL database with products and two different prices.

    Price A has prices on every product while
    Price B only applies to some products as an alternative size.

    How can I hide results of this column where the price is 0.00.

    thanks


Comments

  • Registered Users Posts: 450 ✭✭SalteeDog


    If it was Oracle you could use a 'Decode' function. Perhaps in MySQL it's CASE or IF.


  • Registered Users Posts: 763 ✭✭✭EIREHotspur


    Thanks for that SalteeDog

    Tried a lot of Case examples now with no luck.

    MySQL database is db1 and has
    product_id
    product_name
    product_photo
    price_1
    price_2

    I want to show product_id, product_name and price_1 under product_photo.
    I also want price_2 to appear under each product but only show if the price isn't 0.

    Any examples I see deal with records and not cells or values themselves.


  • Registered Users Posts: 1,034 ✭✭✭dalta5billion


    Thanks for that SalteeDog

    Tried a lot of Case examples now with no luck.

    MySQL database is db1 and has
    product_id
    product_name
    product_photo
    price_1
    price_2

    I want to show product_id, product_name and price_1 under product_photo.
    I also want price_2 to appear under each product but only show if the price isn't 0.

    Any examples I see deal with records and not cells or values themselves.

    How are you displaying the data? Could you filter there? (E.g. PHP or something?)


  • Registered Users Posts: 2,781 ✭✭✭amen


    Does the following work ? I'm not a MySQL guy
    [PHP]

    SELECT
    product_id,
    product_name,
    product_photo,
    price_1,
    CASE
    WHEN price_2 =0 THEN NULL
    ELSE price_2
    END
    FROM
    mytable

    [/PHP]


  • Registered Users Posts: 763 ✭✭✭EIREHotspur


    amen wrote: »
    Does the following work ? I'm not a MySQL guy
    [PHP]

    SELECT
    product_id,
    product_name,
    product_photo,
    price_1,
    CASE
    WHEN price_2 =0 THEN NULL
    ELSE price_2
    END
    FROM
    mytable

    [/PHP]

    Thanks lads...I am going to test out this amen and will tell you if it works.


  • Advertisement
Advertisement