I am still new to SQL. I have been making good progress on my project until I ran into this problem. I have tried to search the net for this kind of problem but I cannot find anything specific to this or I am not using the correct keywords in my search.
I have three tables relevant to this problem. Apparently I do not have any kind of "describe table" command to be able to copy the output. My other queries with joins are working as expected.
Table 1 - "Sites"
ID int auto-increment key, site_code short text, site_name short text, more but not relevant.
Table 2 - "Hubs"
ID int auto-increment key, HUB int (lookup from Sites.ID), more but not relevant.
Table 3 - "DialPlan"
ID int auto-increment key, site int (lookup from Sites.ID), HUB int (lookup from Hubs.HUB), more but not relevant.
When viewing the query for "DialPlan" I need to see "DialPlan.site" being replaced by "Sites.site_code" for that specific int. I need to see "DialPlan.HUB" being replaced by "Sites.site_code" for that specific int. Example of table output without joins:
DialPlan: 28, 29, 2, 203 That last number is not relevant. Sites.ID = 29, Sites.site_name = BENN. Hubs.ID = 2, Hubs.HUB = 27, Sites.ID = 27, Sites.site_name = BRAG. So, the output I need to see when using the join is: 28, BENN, BRAG, 203. I am not getting that, I am getting: 28, BENN, BENN, 203.
My search query is:
select
Sites.site_code, Sites.site_name, Sites.site_code as Hubs.HUB,
DialPlan.OC
from
DialPlan
left join
Sites on DialPlan.site = Sites.ID
left join
Hubs on DialPlan.HUB = Hubs.ID
left join
Hubs on Hubs.HUB = Sites.ID;
I have tried to change field 3 using "AS" and even tried "=" and several other things. If I try to put field 3 as "Sites.site_code" then the output is the same as the first "Sites.site_code" lookup. I am not sure how to proceed. I have tried so many things now that I am not even sure exactly what I have tried. I saw one thread where there were multiple dots per column and I have no idea what that is used for. Does anyone have any ideas?