Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

SQL - Hide Prices where decimal fields are 0

  • 22-06-2013 01:15PM
    #1
    Posts: 0


    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, Registered Users 2 Posts: 450 ✭✭SalteeDog


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


  • Posts: 0 [Deleted User]


    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, Registered Users 2 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, Registered Users 2 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]


  • Posts: 0 [Deleted User]


    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