Firebird Sql Join Tables

Currently I have tables like these:

Table Customer

ID      Name
01      Angel
02      Charlie

Table Input1

Name     Value
Charlie  5
Angel    7
Charlie  10
Angel    3

Table Input2

Name     Value
Charlie  10
Angel    5
Charlie  15
Angel    25

How to get result like this

Name     Input1     Input2
Angel    10         30
Charlie  15         25
6

1 Answer

Try this:

SELECT 
    c.Name, 
    i1."Value" value1, 
    i2."Value" value2
FROM 
    Customer c LEFT JOIN 
    (SELECT Name, SUM("Value") "Value" from input1 group by Name) i1
    ON c.Name = i1.Name LEFT JOIN 
    (SELECT Name, SUM("Value") "Value" from input2 group by Name) i2
    ON c.Name = i2.Name

DEMO

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest