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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

two columns sql join 2

Status
Not open for further replies.

ck1999

Technical User
Dec 2, 2004
784
US
I am trying to join two tables based off the fields salesorderyear and salesordernum

tblA
salesorderyear
salesordrenum

tblb
soyear
sonum

It is a 1:1 relationship. There are a bunch of fields so the tables are divided based on sections of a report.

I am trying to join the data for the report but am not sure since it is two fields instead of 1.

Any help would be appreciated!

ck1999
 

Don't know what your desired output is but you can start with something like:

Code:
select tblA.*, tblB.*
from tblA left join tblB on tblA.salesorderyear = tblB.soyear and tblA.salesordernum = tblB.sonum
order by salesorderyear, salesordernum

That should give you all fields for all records in tblA and all fields for all records in tblB with a sonum and a soyear that match that combination of salesorderyear and saleordernum in tblA.

 
thanks for the help!

How would I accomplish this for a subform?

ck1999
 
A subform allows you you use a composite key for linking. Even if you use the wizard. If you do not use the wizard then seperate the fields with a semicolon

link Master Fields: salesorderyear;saleordernum
link child fields: soyear;sonum

However, there is really no such thing as a 1:1 relationship. All fields that uniquely describe an entity should be in the same table. Designing your database to support a report structure does not make any sense:
"divided based on sections of a report"

There are sometimes legit reasons to split tables; security, limit access to priveledged information, import export restrictions, etc.
 
Thanks majp that did the trick

ck1999
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top