Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel query using SQL inner join command

Posted on 2010-08-17
6
Medium Priority
?
556 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 1500 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

886 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