Skip to content
Advertisement

Postgres join and count multiple relational tables

I want to join the 2 tables to the first table and group by a vendor name. I have three tables listed below.

Vendors Table

VendorOrders Table

OrdersIssues Table

The expected output is to count how many orders belong to a vendor and how many issues belongs to a vendor order.

I have the below code but it’s not giving the right output.

Advertisement

Answer

You need the keyword DISTINCT, at least for allOrders:

Consider using aliases instead of full table names to make the code shorter and more readable.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement