M
Michael_Randall
Syntax for Nested Joins
I have a database with 4 tables and I am trying to query information from 3
of the tables. I would ideally like to obtain the information by using nested
joins instead of 2 separate queries.
Tables/Structures:
CUSTOMER(CustomerPK, Name, Phone, EmailAddress)
APPLIANCE(SerialNumber, Type, Version, DateofCreation)
APPLIANCE_REPAIR(InvoiceNumber, SerialNumber, DateRepair, Description, Cost,
CustomerPK)
I would like to get a list of all repairs in the APPLIANCE_REPAIR table,
specifically, InvoiceNumber, SerialNumber, and Description. From the
APPLIANCE table I would like to get the corresponding Type of appliance. And,
from the CUSTOMER table I would like the corresponding customer Name and
Phone number.
Current multi-query solution:
First Query
SELECT S.Type, SR.RepairInvoiceNumber, SR.SerialNumber, SR.Date,
SR.Description, SR.Cost, SR.CustomerSK
FROM STOVE AS S RIGHT JOIN STOVE_REPAIR AS SR ON
S.SerialNumber=SR.SerialNumber;
Second Query
SELECT RepairDetailsType.*, CUSTOMER.Name, CUSTOMER.Phone
FROM RepairDetailsType INNER JOIN CUSTOMER ON RepairDetailsType.CustomerSK =
CUSTOMER.CustomerSK;
As I asked before, is this possible to achieve by using nested joins all in
one query? I've tried to solve this myself but was unable to.
I have a database with 4 tables and I am trying to query information from 3
of the tables. I would ideally like to obtain the information by using nested
joins instead of 2 separate queries.
Tables/Structures:
CUSTOMER(CustomerPK, Name, Phone, EmailAddress)
APPLIANCE(SerialNumber, Type, Version, DateofCreation)
APPLIANCE_REPAIR(InvoiceNumber, SerialNumber, DateRepair, Description, Cost,
CustomerPK)
I would like to get a list of all repairs in the APPLIANCE_REPAIR table,
specifically, InvoiceNumber, SerialNumber, and Description. From the
APPLIANCE table I would like to get the corresponding Type of appliance. And,
from the CUSTOMER table I would like the corresponding customer Name and
Phone number.
Current multi-query solution:
First Query
SELECT S.Type, SR.RepairInvoiceNumber, SR.SerialNumber, SR.Date,
SR.Description, SR.Cost, SR.CustomerSK
FROM STOVE AS S RIGHT JOIN STOVE_REPAIR AS SR ON
S.SerialNumber=SR.SerialNumber;
Second Query
SELECT RepairDetailsType.*, CUSTOMER.Name, CUSTOMER.Phone
FROM RepairDetailsType INNER JOIN CUSTOMER ON RepairDetailsType.CustomerSK =
CUSTOMER.CustomerSK;
As I asked before, is this possible to achieve by using nested joins all in
one query? I've tried to solve this myself but was unable to.