SimonPGreen
IS-IT--Management
Hi all,
Can anyone help with the syntax (if its possible) to achieve the following in one SELECT statement:
Have 2 Access DB's
DB 1 has 3 tables; tblcontracts/tbljobcards/tblbookings
DB 2 has 3 tables; tblpricecontracts/tblpricejobcards/tblpricepricework
Tables are all the same structure adn relationships.
The first DB has links to the second so that all tables are available for query in DB 1.
I have produced SQL as follows to list all contracts respectively for paid hours and pricework(cut down versions)
Statement 1
select tblcontracts.contractref,tblcontracts.contractname,tblbookings.basic
from tblcontracts
inner join
tbljobcards
on tblcontracts.contractid = tbljobcards.contractd
inner join
tblbookings
on tbljobcards.jobcardid = tblbookings.jobcardid
group by ..... etc
Statement 2
select tblpricecontracts.contractref,tblpricecontracts.contractname,tblpricework.price
from tblpricecontracts
inner join
tblpricejobcards
on tblpricecontracts.contractid = tblpricejobcards.contractd
inner join
tblpricework
on tblpricejobcards.jobcardid = tblpricepricework.jobcardid
group by ..... etc
I obviously now have two SQL queries that both have a related contractid value but I can't work out how to write a single set of join statements that can combine all of the tables as they fork off from two common tables.
PS I know that the DB design should really have been a single DB but this is what I have got.
I have managed to write a query that calls the first two queries and achieves the objective but I am interested if there is a better way
Kind Regards,
Simon Green
Can anyone help with the syntax (if its possible) to achieve the following in one SELECT statement:
Have 2 Access DB's
DB 1 has 3 tables; tblcontracts/tbljobcards/tblbookings
DB 2 has 3 tables; tblpricecontracts/tblpricejobcards/tblpricepricework
Tables are all the same structure adn relationships.
The first DB has links to the second so that all tables are available for query in DB 1.
I have produced SQL as follows to list all contracts respectively for paid hours and pricework(cut down versions)
Statement 1
select tblcontracts.contractref,tblcontracts.contractname,tblbookings.basic
from tblcontracts
inner join
tbljobcards
on tblcontracts.contractid = tbljobcards.contractd
inner join
tblbookings
on tbljobcards.jobcardid = tblbookings.jobcardid
group by ..... etc
Statement 2
select tblpricecontracts.contractref,tblpricecontracts.contractname,tblpricework.price
from tblpricecontracts
inner join
tblpricejobcards
on tblpricecontracts.contractid = tblpricejobcards.contractd
inner join
tblpricework
on tblpricejobcards.jobcardid = tblpricepricework.jobcardid
group by ..... etc
I obviously now have two SQL queries that both have a related contractid value but I can't work out how to write a single set of join statements that can combine all of the tables as they fork off from two common tables.
PS I know that the DB design should really have been a single DB but this is what I have got.
I have managed to write a query that calls the first two queries and achieves the objective but I am interested if there is a better way
Kind Regards,
Simon Green