I need help in creating a query for my database.
I have 2 tables,
asset which consists of (hostname, owner, engineer, date, branch)
branch which consists of (id, name, address, region)
branch.id is a primary key which is connected to asset.branch which is obviously a foreign key.
I wanted to create a query that displays the branch information (id, name, address, region) and the number of assets in that branch.
I tried this query:
SELECT b.id, b.name, b.address, b.xcor, b.ycor, b.status,
COUNT(a.hostname) AS noofasset
FROM branch b, asset a
WHERE a.branch = b.id
GROUP BY b.id;
It worked at a glance, but failed to display branch information that has no assets in it.
I need a query that also displays branches that have 0 asset.
LEFT join says include all branches regardless if an asset exists.
This site explains left, right outer full and types of joins visually.. I liked it 😀
Using the syntax you’re more familiar with (I think)