I have 3 tables relationship called tblCluster, tblServer, and tblDatabase. Server is under Cluster and Database is under Server. PK in tblCluster is ClusterName. Pk in tblServer is ServerName and FK is ClusterName. PK in tblDatabase is DatabaseName and FK is Servername. If I want to see all ServerName and DatabaseName under/from ClusterName is Cluster5. Should I write query like
SELECT tblCluster.ClusterName, tblServerName.ServerName, tblDatabase.DatabaseName
FROM tblCluster
JOIN tblServer
ON tblCluster.ClusterName = tblServer.ClusterName
INNER JOIN tblDatabase
ON tblServer.ServerName = tblDatabase.ServerName
WHERE tblCluster.ClusterName = Cluster5;
If servername is found even database is empty I still want it display result table of with datbasename null.
Have you tried using
LEFT JOINinstead ofINNER JOIN– this is typically the solution for such requirements. Look here for a more detailed explanation containing some examples.