473,396 Members | 1,599 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.

Complex join

Hi,

I'm having a problem linking 4 tables in MYSQL. The first table contains
customer details, the next item details and the next 2 contain sales
information. The final output of the query should be:-

CustomerName Item Sales2002 Sales2003

(customers.name) (items.inum) (sales2002.val) (sales2003.val)

Test One ABM10 100 200

Test One ABM11 200 300

Test Three RJM10 200 400

Test Three SLP02 800 50

The table structures are as follows:-

Customers

ID Unique Record identifier

Name Customer Name

Items

ID Unique Record identifier

INUM Item Number

DESC Description

SALES2003 and SALES2002

ID Unique Record identifier

PID Part number ID

CID Customer ID

VAL Sales Value

I am new to SQL and have tried a number of different joins but I always seem
to get duplicate data. If anyone is able to tell me what type of join I need
to use or perhaps know of a way to format these tables in the required
layout that would be great.

Thanks in advance

Dave


Jul 20 '05 #1
2 1444
i'm not a good answerer but since no one has had a go...

if it could be assummed that one sales tables covers all customers/items
that the other sales tables has, then from this "bigger" table do outer
joins to the customer table, the items table, and the other sales table.
When joining to the other sales table, need to involve both the
customer id and the item id.

hope that makes some sense.
David Richards wrote:
Hi,

I'm having a problem linking 4 tables in MYSQL. The first table contains
customer details, the next item details and the next 2 contain sales
information. The final output of the query should be:-

CustomerName Item Sales2002 Sales2003

(customers.name) (items.inum) (sales2002.val) (sales2003.val)

Test One ABM10 100 200

Test One ABM11 200 300

Test Three RJM10 200 400

Test Three SLP02 800 50

The table structures are as follows:-

Customers

ID Unique Record identifier

Name Customer Name

Items

ID Unique Record identifier

INUM Item Number

DESC Description

SALES2003 and SALES2002

ID Unique Record identifier

PID Part number ID

CID Customer ID

VAL Sales Value

I am new to SQL and have tried a number of different joins but I always seem
to get duplicate data. If anyone is able to tell me what type of join I need
to use or perhaps know of a way to format these tables in the required
layout that would be great.

Thanks in advance

Dave


Jul 20 '05 #2
I'll give it a go.

Thanks for the reply.
Dave
"David Richards" <da**@tools.co.uk> wrote in message
news:ca**********@hercules.btinternet.com...
Hi,

I'm having a problem linking 4 tables in MYSQL. The first table contains
customer details, the next item details and the next 2 contain sales
information. The final output of the query should be:-

CustomerName Item Sales2002 Sales2003

(customers.name) (items.inum) (sales2002.val) (sales2003.val)

Test One ABM10 100 200

Test One ABM11 200 300

Test Three RJM10 200 400

Test Three SLP02 800 50

The table structures are as follows:-

Customers

ID Unique Record identifier

Name Customer Name

Items

ID Unique Record identifier

INUM Item Number

DESC Description

SALES2003 and SALES2002

ID Unique Record identifier

PID Part number ID

CID Customer ID

VAL Sales Value

I am new to SQL and have tried a number of different joins but I always seem to get duplicate data. If anyone is able to tell me what type of join I need to use or perhaps know of a way to format these tables in the required
layout that would be great.

Thanks in advance

Dave


Jul 20 '05 #3

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

Similar topics

1
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes...
4
by: Christoph Bisping | last post by:
Hello! I'm seeking advice on a rather complex type of query I need to build in an Access ADP (SQL-Server 7). There are four tables: tblPeople ID(PK) PRENAME --------------- 1 Thomas 2 Frank
1
by: Beachvolleyballer | last post by:
hi there anyone had an idea to join following 2 queries to 1???? ----- QUERY 1 --------------------------------------------- SELECT TMS_CaseF_2.Name AS TCDomain_0, TMS_CaseF_3.Name AS...
0
by: schan | last post by:
Hi there, I was wondering if someone could shed some light on a problem I have no idea on how to fix. I created an Excel Add-In that uses an ADO connection to an Access database on a file...
6
by: Jon Bilbao | last post by:
I´m trying a select clause in two steps because it´s too complex. First: SELECT Reference, Results.idEnsayo, Results.Num_taladro, min(Results.dTime) + 500 AS tIni, max(Results.dTime) - 500 AS...
2
by: mgsn | last post by:
I Have This this Query --------------------------------- set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER proc . @userId int=null, -- filter: user id. overrides custid when supplied ...
1
by: Vivienne | last post by:
Hi there This is a hard problem that I have - I have only been using sql for a couple of weeks and have gone past my ability level quickly! The real tables are complex but I will post a simple...
3
blyxx86
by: blyxx86 | last post by:
Hey there, I'm running into a slight problem today... I have a few things to show... I'm running into duplicate values being shown in my query, but I cannot use a "Select DISTINCT" as it...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
crystal2005
by: crystal2005 | last post by:
Hi, I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.