Solved

Excel query using SQL inner join command

Posted on 2010-08-17
6
486 Views
Last Modified: 2012-05-10
I am retrieving inventory information from a Pervasive db using excel query. I need the inventory info from 2 different tables. I want the results on 1 worksheet. The product number is the common field in both tables so I use INNER JOIN to get the price for the product (Price table) and match it to the stock name and quantities (inventory table). However the results give me duplicates (sort of). I get results with each product listed on 2 rows. One row has all of the stock information from the Inventory table as well as the pricing from the Price Tables (just what I want) however there is also a second row with just the results from the inventory table and 0 for price. How do i fix this?
SELECT partnum, description, price1, wholesale, ave_cost, on_hand FROM inventory, pricing
WHERE partnum = pricepartnum

Open in new window

0
Comment
Question by:RTsal
6 Comments
 
LVL 11

Accepted Solution

by:
Larissa T earned 500 total points
Comment Utility
SELECT partnum, description, price1, wholesale, ave_cost, on_hand FROM inventory, pricing
WHERE partnum = pricepartnum and price1 <> 0
0
 
LVL 16

Expert Comment

by:vdr1620
Comment Utility
SELECT partnum, description, price1, wholesale, ave_cost, on_hand
FROM inventory I INNER JOIN pricing P
ON I.partnum = P.pricepartnum
WHERE P.Price !=0
0
 
LVL 1

Expert Comment

by:geonon
Comment Utility
try this:

SELECT inv.partnum, inv.description, pri.price1, pri.wholesale, pri.ave_cost, inv.on_hand
FROM inventory Inv, pricing pri
WHERE inv.partnum = pri.pricepartnum and price1 <> 0

I add alias and one more condition on where.

best

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
0
 

Author Closing Comment

by:RTsal
Comment Utility
This solves the problem but does not answer why the results returned 2 rows for every product number with one row containing a price of 0 and the other row containing the correct price
0
 
LVL 11

Expert Comment

by:Larissa T
Comment Utility
It depends on usage and maintenance of pricing table
May be rows with 0 are used to list all products available in your system. Or it could be some errors in your system that inserted rows with price 0  or some leftover from debugging...

Run this
SELECT *
FROM pricing P WHERE P.Price =0
to see all those rows.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now