Solved

Excel query using SQL inner join command

Posted on 2010-08-17
6
515 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
ID: 33458308
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
ID: 33458648
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
ID: 33458754
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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33458831
0
 

Author Closing Comment

by:RTsal
ID: 33463452
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
ID: 33464719
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

789 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