Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple table join

Status
Not open for further replies.

wickyd

Technical User
Feb 14, 2002
57
ZA
Hi

I have two tables. One with Nettsales for a customer, which looks like:
[tt]
ACCNUM NETTSALES
ABC001 R 100 000
ABC002 R 123 456
XYZ001 R 225 000
etc.
[/tt]
I have another table, which looks like this
[tt]
ACCNUM REP
BAA001 1
BAA002 2
etc ...
ABC001 3
ABC002 1
etc ...
XYZ001 4
etc
[/tt]
What SQL do I use to get:
[tt]
ACCNUM NETTSALES REP
ABC001 R 100 000 3
ABC002 R 123 456 1
XYZ001 R 225 000 4
[/tt]
Thank you.
 
Hi Wickyd.

Select c.accnum, c.nettsales, r.rep
From [nettsalestable] c inner join [repstable] r
on c.Accnum=r.Accnum

If one of your tables is related one to many (e.g. one REP->several Nettsales entries), oyu need a LEFT JOIN instead of an inner join.

Else, simply replace nettsalestable and repstable with the correct table names.

Should do fine,
Andy

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top