473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

(Newbie) Join problem.

Hi,
I'm new to SQL trying to use a base that was set up by another firm.
I can't get it to do what I want and I don't know if it's due to my
ignorance or bad table design ...

I have three tables
Sales
containing ProdID and Amounts

Products
containing ProdID and ProdTypeID and
ProdSubTypeID

Product-types
containing ProdTypeID and ProdTypeIDLabel and
ProdSubTypeID and ProdSubTypeIDLabel

I have to do some stats in Excel or in Crystal
totalling Amounts
grouped by ProductTypeLabel and
grouped by ProductSubTypeLabel.

Here's what I can do...
------------------------------
Using ProdTypeID, I can join Product-Types to Products,
and
using ProdID, I can join Products to Sales
and get a sum of amounts grouped by ProductTypeLabel. OK.

Also,
Using ProdTypeID, I can join Product-Types to Products,
and
using ProdID, I can join Products to Sales
and get a sum of amounts grouped by ProductSubTypeLabel. OK.
Here's what I can't do...
------------------------------
Get both (i.e. ProductTypeLabel and ProductSubTypeLabel) in the same report
and the correct amounts.

I have found a solution but it involves modifying the tables.
I create a new field with the Type and SubType concatenated in Products and
also in Product-Types (ProductTypeGlobal) and then join on that.
So,
Using ProductTypeGlobal, I can join Product-Types to Products,
and
using ProdID, I can join Products to Sales
and get a sum of amounts
grouped by ProductTypeLabel
AND
grouped by ProductSubTypeLabel
OK.

Is there some way to create the correct joins in SQL without creating the
new field?

Thanks

SQL Newbie.


Jun 1 '08 #1
0 1254

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruce Duncan | last post by:
I'm a bit new to MySQL (know MS SQL well...and that may be the problem...getting the syntax confused) and I'm having a join problem...can anyone offer some help? Here's my problem: I have table1...
7
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem that we fixed, but I'd like to understand 'why' it...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
2
by: accessnovice | last post by:
Hello All! I am new to programming in the MS Access environment and decided to join this community due to various problems I encountered in Access 2000 and 2003. I began a small project in Access...
1
by: taoh15 | last post by:
Hi All Although I have been using SQL2K for a number of years this is my first venture into more complicated stuff. I have a query SELECT apd.elid , apd.pcid , apd.apstatid , ap.empid ...
3
by: Phillip B Oldham | last post by:
Hi. I'm stretching my boundaries in programming with a little python shell-script which is going to loop through a list of domain names, grab the whois record, parse it, and put the results into a...
17
by: takayuki | last post by:
Hi, I'm studying python via the exellent book "How to think like a python programmer" by Allen Downey. Noob question follows... animals.txt is a list of animals, each on a separate line:...
0
by: SQL-Newbie | last post by:
Hi, I'm new to SQL trying to use a base that was set up by another firm. I can't get it to do what I want and I don't know if it's due to my ignorance or bad table design ... I have three...
2
Lokean
by: Lokean | last post by:
Okay, this works, but there has GOT to be a cleaner way of doing this. Suggestions please. DECLARE @TMP TABLE ( HOLD1 NUMERIC, HOLD2 NUMERIC, HOLD3 NUMERIC, HOLD4 NUMERIC,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.