sql server - SQL - Query Join result is empty even though there are data in one of the tables -
i have 2 tables named tnetworksocket
, tpatchpanelports
use filter data.
have data when execute select * tpatchpanelports
but, when select * tnetworksocket
there no data. correct.
if execute
select distinct hostid, hostname, hosttypeid, domainname thosts, tdomains, tpatchpanelports, tnetworksocketport thosts.domainid=tdomains.domainid , ( tpatchpanelports.connectedhostid = thosts.hostid or tnetworksocketport.connectedhostid = thosts.hostid) , accountid=1
i no data, if remove tnetworksocketport
query looks like:
select distinct hostid, hostname, hosttypeid, domainname thosts, tdomains, tpatchpanelports thosts.domainid=tdomains.domainid , ( tpatchpanelports.connectedhostid = thosts.hostid) , accountid=1
i data.
what missing
re-writing query explicit join syntax , table have used left join, may you
select distinct hostid, hostname, hosttypeid, domainname thosts inner join tdomains on thosts.domainid=tdomains.domainid inner join tpatchpanelports on tpatchpanelports.connectedhostid = thosts.hostid left join tnetworksocketport on tnetworksocketport.connectedhostid = thosts.hostid accountid=1
Comments
Post a Comment