Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3431652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:21:10+00:00 2026-05-18T07:21:10+00:00

I’m currently working on a proprietary shopping cart system and was having a few

  • 0

I’m currently working on a proprietary shopping cart system and was having a few problems with getting products out with the correct pricing.

Basically my table structure is as follows:

Products table: (Only relevant columns are represented)

----------------------------------------------------
productid | product | descr | disporder| list_price|
----------------------------------------------------
    1        name      desc      1          0.00
    2        name      desc      4          0.00
    3        name      desc      2          2.45

Pricing table:

----------------------------------------
priceid | productid | price | variantid|
----------------------------------------
    1         1       13.91      1
    2         2       54.25      4
    3         2       47.23      2

Variants Table:

-------------------------------
variantid | productid | active|
-------------------------------
    1          1          Y     
    2          2          Y
    3          2          Y

So, each product can have – and in most cases does have – multiple variants. My current SQL query I have managed to create thus far is:

    SELECT 
        products.productid, product, descr, p.price, i.image_path
    FROM 
        products
    LEFT JOIN 
        pricing AS p 
    ON  
        p.variantid = (SELECT variantid FROM variants 
            WHERE productid = products.productid LIMIT 1)
    LEFT JOIN 
        images_T AS i 
    ON
        i.id = products.productid
    GROUP BY
        products.productid
    ORDER BY
        products.disporder

However, my problem arises when a product does not have a variant. If a product does not have a variant associated with it, the price will be in the list_price column of the products table. How would I go about performing a check to see if a product does indeed have a variant. If not, it should effectively bypass the variants table and get the pricing from list_price within the products table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T07:21:10+00:00Added an answer on May 18, 2026 at 7:21 am

    Yes, CASE is an option, or COALESCE:

    SELECT 
        products.productid, product, descr, 
        COALESCE(products.list_price, p.price) AS price, 
        i.image_path
    ...
    

    Just join both prices and when the first is NULL the other will be selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.