Solved

Query Help

Posted on 2011-09-24
2
287 Views
Last Modified: 2012-05-12
I'm trying to return only 1 row for each order.
An order can have multiple line items.

I want to check each line item to make sure the quantity in stock is greater than 0.
Right now, there is an order that has two lines and both are in stock, but I just want it to return one row.
I pretty much just need a couple columns from the orders table and not the line items table.

SELECT
      *
FROM Orders a
INNER JOIN LineItems b
ON a.OrderID = b.OrderID
INNER JOIN Products c ON c.ProductID = b.ProductID
WHERE
      c.QuantityInStock > 0
AND
      a.OrderStatusID = 1
AND
      a.GatewaySuccessful = 1
AND
      a.ToBePrinted = 1
0
Comment
Question by:JRockFL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36592383
Then try something like this:

SELECT
      a.ColumnX, a.ColumnY, a.ColumnZ
FROM Orders a
INNER JOIN LineItems b
ON a.OrderID = b.OrderID 
INNER JOIN Products c ON c.ProductID = b.ProductID
WHERE
      c.QuantityInStock > 0
AND 
      a.OrderStatusID = 1
AND 
      a.GatewaySuccessful = 1
AND 
      a.ToBePrinted = 1
GROUP BY
      a.ColumnX, a.ColumnY, a.ColumnZ

Open in new window

0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 36592395
Awesome, thank you
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question