SQL Query with table joins

HI

What would the SQL query be to select all fields from the table shown in the image.
I used Access to get the image but want to understand how someone would ma manually
write the SQL script to pull data from multiple joined tables.

1
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dukster131Commented:
First, the mapping for the tables is wrong.  Everything is going to feed into Jobs.  I would assume that you have a ClientID in Jobs.  If you have multiple contacts you may have to have multiple links with the Contacts using aliases for the Contacts table.  Alternatively you could create a juntion table that links Contact_ID to Job ID.  The same thing is true for the materials table.  A junction table would be most appropriate for multiple Materials per job linking Job ID and Materials ID.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. Thanks. I am really just looking for an example of 3 or four tables that are all linked together. Jobs does have a ClientID. I just need some direction on linking multiple tables
0
Dukster131Commented:
Select(whatever you want to select in the tables)
from Jobs j
inner join Clients c on j.ClientID=c.ClientID
inner join Materials m on m.materialsID = j.materialsID
inner join Contacts s on s.Contact_ID = j.Contact_ID

If you are not always getting a Client or contact, then you may have to do outer joins.
0
Steve WalesSenior Database AdministratorCommented:
As a general example of joining multiple tables into a single query, let's assume we have  tables:

Suppliesr - supplier_no, supplier_name
orders - order_no, supplier_no, order_date
order_items - order_no, order_item_no, stock_item
stock - stock_item, stock_item_name

If you wanted to pull all the details for an order:

select a.order_no, a.supplier_no, a.order_date, b. order_item_no, b.stock_item, d.stock_item_name
from orders a
join order_items b on a.order_no = b.order_no
join suppliers c on a.supplier_no = c.supplier_no
join stock d on b.stock_item = d.stock_item

Open in new window


Start with the base query on the table that drives your query

Add in tables with joins one at a time to build your query.
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for the help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.