32ozWaterBottle
New member
- Local time
- Today, 06:21
- Joined
- Jan 28, 2020
- Messages
- 3
Hello,
I have two tables:
tblStreet
Street ID
StreetName
and
tblCellTowerLocation
CellTowerID
OnStreetID
AtStreetID
I am trying to link StreetID in a 1-to-many relationship with OnStreetID and AtStreetID . After that, i want to do a query to display tblCellTowerLocation with the StreetName instead of the actual IDs for OnStreetID and AtStreetID. Using the Access GUI, I can only query one column (OnStreetID) to display StreetName. When I add a second StreetName, it repeats OnStreetID.
I asked a friend and they provided me a SQL query. However, Access does not allow for CTEs. The 'WITH' function does not work. Is there a way to write a SQL query around a CTE such as using a subquery for this scenario? Or am I missing something really simple? Or is my database design incorrect?
The following is the SQL query I was provided:
Thanks.
I have two tables:
tblStreet
Street ID
StreetName
and
tblCellTowerLocation
CellTowerID
OnStreetID
AtStreetID
I am trying to link StreetID in a 1-to-many relationship with OnStreetID and AtStreetID . After that, i want to do a query to display tblCellTowerLocation with the StreetName instead of the actual IDs for OnStreetID and AtStreetID. Using the Access GUI, I can only query one column (OnStreetID) to display StreetName. When I add a second StreetName, it repeats OnStreetID.
I asked a friend and they provided me a SQL query. However, Access does not allow for CTEs. The 'WITH' function does not work. Is there a way to write a SQL query around a CTE such as using a subquery for this scenario? Or am I missing something really simple? Or is my database design incorrect?
The following is the SQL query I was provided:
Code:
WITH OnStreetName
AS(
SELECT
SL.CellTowerID,
S.StreetName AS
OnStreetName
FROM
Streets S
INNER JOIN CellTower SL
ON S.StreetID = SL.OnStreetID
),
AtStreetName
AS(
SELECT
SL.CellTowerID,
S.StreetName AS AtStreetName
FROM
Streets S
INNER JOIN CellTower SL
ON S.StreetID = SL.AtStreetID)
SELECT
SL.CellTowerID,
OSN.OnStreetName,
ASN.AtStreetName
FROM
OnStreetName OSN
INNER JOIN AtStreetName ASN
ON OSN.CellTower.ID=ASN.CellTowerID
Thanks.