Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Forming the Join ~ WHERE Clause There are many ways to form a join between tables. The most universal is using the WHERE clause. .
Forming the Join ~ WHERE Clause
There are many ways to form a join between tables. The most universal is using the WHERE clause.
guidesimgdisplayimage
As you can see from the diagram above, the primary key of one table needs to equal the foreign key of the other table in order for rows to be returned. We keep adding to this list as we include more tables in the join. Also notice how we include any filters the query may need within this statement.
To demonstrate this type of join, we are going to produce a report showing the Customer Last Name, the Order ID and the Order Date for all orders placed in The join for this table, as we already know is PersonID CustomerID. To run this query we need to load the Auntie B Database.
LOAD AUNTIE BS DATABASE
Here is the query:
use auntieb;
select lastname
orderid
orderdate
from People, Orders
where people.peopleid orders.customerid
and yearorderdate;
TRY IT
Your results should look like the following:
lastname orderid orderdate
Jackson
Jackson
rows affected
The only negative to using this method is how cluttered the WHERE clause can quickly become if we need to add more filters. The more cluttered, the harder it is to debug if there is something wrong with your query. This is why I prefer the next join method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started