Skip to content
Advertisement

How can I get a value when the master table of the outer join is empty?

I have created a table where I get the sum of each item.

However, this query returns : 0 row affected.

I know what the problem is. If the key_id and cust_id are not in the t1 table specified as an alias, the value cannot be returned because the t1 table is empty.

If there is data for key_id in t1, this query works fine. However, there may be no data in t1. How can I solve this problem?

Advertisement

Answer

You want a full join, which MySQL does not support. There are various ways to approach this, but perhaps the simplest in your case is union all with aggregation afterwards:

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