Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Count values in a query

Posted on 2012-12-27
7
Medium Priority
?
352 Views
Last Modified: 2012-12-27
I have a query in which I query ten tables for cross reference information.

Each table has
Item_nr
Vendor_item_nr
Price

My master table has
Item_nr
30 other fields

My query selects Vendor_item_nr from each table where Item_Nr=tbl_master!item_nr

My results
Item_nr, tbl_1!Vendor_item_nr, tbl_2!Vendor_item_nr, tbl_3!Vendor_item_nr...ect

How can I count the number of Vendor_item_nr results returned for each Item_nr?
0
Comment
Question by:MCaliebe
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 26

Assisted Solution

by:jerryb30
jerryb30 earned 400 total points
ID: 38724747
SELECT master.item_nr, table1.vendor_item_nr, "table1" AS Source
FROM master INNER JOIN table1 ON master.item_nr = table1.item_nr
union all
SELECT master.item_nr, table2.vendor_item_nr, "table2" AS Source
FROM master INNER JOIN table2 ON master.item_nr = table2.item_nr
union all
SELECT master.item_nr, table3.vendor_item_nr, "table3" AS Source
FROM master INNER JOIN table3 ON master.item_nr = table3.item_nr

etc

Then:
Select Item_nr, count(vendor_item_nr) from yourQuery
group by item_nr
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38724748
You need to  get rid of the 10 separate (Vendor) tables and normalize that data into a single table with fields:

VendorID
Item_nr
Vendor_item_nr
Price

With that type of a structure, you simply count the number of VendorID values for each Item_Nr.

You could accomplish the same thing with a normalizing query, but having separate tables for each vendor makes the entire database application far more complex than it needs to by.
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 38724750
Meant to say: Create a union query, and use as source of count query.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:MCaliebe
ID: 38724778
I was given each vendor as it's own spread sheet.  I admit I thought about putting them all together, however not all the vendors use a unique vendor_item_nr so I could have 3 vendors with unique Vendor_item_nr and 3 using the same. I needed to keep each record identified back to the vendor as well.  Some vendors have multiple prices as well.
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 600 total points
ID: 38724823
A lot of vendors have multiple prices based on the way the items are packaged, so create a single table with:

VendorID
Item_nr    'I assume this is your item number
Vendor_item_nr
Pckg          'this might be 'each', 'Pack of 10', 'Pack of 100', 'Box of 500'  whatever
Price

and vendor prices will also change, so it is common to include an Effective Date (and possibly Thru Date) in tables like this so you can keep track of the effective date of a price and how long it is good for.
0
 

Author Closing Comment

by:MCaliebe
ID: 38724850
Although I'm certain Jerry's solution would work, I think the best solution for me is to do as fyed suggest and try to combine this data in a more data friendly format.  I'll probably have to ask this questions again, however at this time...I'll work with the data.
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38724880
You can use Jerry's union query to get the data into a normalized format I recommended.  That is where you need to start.  Then create a Make-Table query from the union query to create the new normalized table.  As long as you don't delete the original 10 vendor tables, you can tweak that union query until you get the structure the way you want it.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

670 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