PHP - error when joining fields from different SQL databases -
i trying build query return results 3 different tables per following:
events table datetime, direction, devicename
tenants tenantname
individuals firstname, lastname
initially i've returned fields first 2 tables following sql:
select eventtime, devicename, comment, tenantname taclogdata.dbo.event inner join inetdb.dbo.tenants on taclogdata.dbo.event.tenant = inetdb.dbo.tenants.tenantid taclogdata.dbo.event.eventtime between '01/04/2014 16:00:00' , '01/04/2014 16:00:59
i've joined both event , tenants tables using tenantid field.
i needed return fields firstname , lastname (from individuals table), tried using sql below:
select eventtime, devicename, comment, tenantname, firstname, lastname taclogdata.dbo.event inner join inetdb.dbo.tenants on taclogdata.dbo.event.tenant = inetdb.dbo.tenants.tenantid inner join inetdb.dbo.tenants on inet.dbo.tenants.tenantid = inet.dbo.individuals.tenantndx taclogdata.dbo.event.eventtime between '01/04/2014 16:00:00' , '01/04/2014 16:00:59'
however returned following error:
the objects "inetdb.dbo.tenants" , "inetdb.dbo.tenants" in clause have same exposed names. use correlation names distinguish them.
can please guide me on how it's best resolve please ?
updated
i've modified syntax below:
select eventtime, devicename, comment, tenantname, firstname, lastname taclogdata.dbo.event inner join inetdb.dbo.tenants on taclogdata.dbo.event.tenant = inetdb.dbo.tenants.tenantid inner join inetdb.dbo.individuals on inetdb.dbo.tenants.tenantid = inetdb.dbo.individuals.tenantndx taclogdata.dbo.event.eventtime between '01/04/2014 16:00:00' , '01/04/2014 16:00:59'
i received following error:
msg 209, level 16, state 1, line 1 ambiguous column name 'firstname'. msg 209, level 16, state 1, line 1 ambiguous column name 'lastname'
you missing individuals
table in inner join , use tenants
mistake.
select eventtime, devicename, comment, tenantname, inetdb.dbo.individuals.firstname, inetdb.dbo.individuals.lastname taclogdata.dbo.event inner join inetdb.dbo.tenants on taclogdata.dbo.event.tenant = inetdb.dbo.tenants.tenantid inner join inetdb.dbo.individuals on inetdb.dbo.tenants.tenantid = inetdb.dbo.individuals.tenantndx taclogdata.dbo.event.eventtime between '01/04/2014 16:00:00' , '01/04/2014 16:00:59'
Comments
Post a Comment