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 6857405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:00:50+00:00 2026-05-27T02:00:50+00:00

I am very new to SQL, so I am having a couple problems figuring

  • 0

I am very new to SQL, so I am having a couple problems figuring things out. The database is for an online store, and the structure is something like this:

users: UserID, UserName, etc.

pricelists: PricelistID, UserID, ProductItemID, Price

productitems: ProductItemID, ProductID, ItemID

products: ProductID, ManufacturerID, WebPageText, etc.

Each product can have one or more items (e.g. if the product page is selling T-shirts, there may be 5 different T-shirt variations for sale). That’s pretty normal. What’s not normal is that the pricing for each item is determined by what’s in the user’s pricelist, because each user is assigned particular pricing. Not all users have a price assigned for every item.

Here is the question: The requirement from management is that the user should be able to see every product, even if that product is not in the user’s pricelist. If the user has no pricelist entry for a productitem, the page should display, “Contact us for pricing.” I have not been able to figure out how to do this with one query. Every join that I attempted involving the pricelist table threw out products for which the user didn’t have a price assigned. I am given only the ProductID and UserID. I have put my code below, which is a mix of mysql and PHP. It works, but it is clunky, especially seeing as I have to redo the second query over and over. Please tell me how I really ought to be doing it.

$query_product = sprintf("SELECT * , (items.Stock - (SELECT Coalesce(Sum(DetailQuantity),0) 
FROM orderdetails 
INNER JOIN orders ON OrderID = DetailOrderID 
INNER JOIN productitems ON orderdetails.ProductItemID = productitems.ProductItemID
INNER JOIN products ON productitems.ProductID = products.ProductID
INNER JOIN items ON productitems.ItemID = items.ItemID
WHERE OrderDate > ProductUpdateDate))*ProductLive 
AS NumLeft
 FROM productitems
 INNER JOIN products ON products.ProductID = productitems.ProductID
JOIN items ON productitems.ItemID = items.ItemID
WHERE products.ProductID = %s",GetSQLValueString($ProductID, "int"));
$product = mysql_query($query_products, $x) or die(mysql_error());
$row_product = mysql_fetch_assoc($product);

//after narrowing down to one productitem, either through user selections or while looping through $row_product:

$query_price = sprintf("SELECT Price FROM pricelists 
WHERE UserID = %s AND ProductItemID = %s", GetSQLValueString($UserID, "int"), GetSQLValueString($row_product['ProductItemID'], 'int'));
$price = mysql_query($query_price, $x) or die(mysql_error());
$row_price = mysql_fetch_assoc($price);
$row_product['Price'] = $row_price['Price'];

Later in the code, I check whether $row_products[‘Price’] is empty or not to determine what is displayed on the page.

EDIT: I thought this would be obvious, but … I have to limit pricelists by WHERE UserID = %s. That means I can’t just tack on a LEFT JOIN pricelists ON pricelists.ProductItemID = productitems.ProductItemID, which was actually the first thing I tried, and which does not work. Limiting the outer join in the WHERE statement turns it into an inner join.

  • 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-27T02:00:51+00:00Added an answer on May 27, 2026 at 2:00 am

    Add the pricelists table as an LEFT join to your main query:

    SELECT field1, field2, ..., pl.*
    FROM orderdetails 
    INNER JOIN orders ON OrderID = DetailOrderID 
    ...
    LEFT JOIN pricelists pl PN pl.ProductItemID = productitems.ProductItemID
    ..
    

    In your code check if the price in the pricelists table is null, if so, show the text.

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

Sidebar

Related Questions

Im very new to SQL but need to write a query to do the
Hi I'm very new to sql but have been passed a job in which
I am a very experienced MS Sql developer, and a few new job positions
I am very new to SQL and am using SQLite 3 to run basket
Very new to Business Objects, but I have a .NET background and PL/SQL background.
I'm having newsequentialid() learning problems in sql server management studio. Create a table with
I am new to Linq to SQL, but I am surprised at the problems
I need to insert many sql rows into oracle database very fast. IndexData is
I am quite new at SQL statements and I have never been very good
I'm trying to learn LINQ to SQL but having a very difficult time. I

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.