I am new to using sql .i have two table expense statement and revenue statement such as

revenue statement
accountname debit
A 100
B 200


expense statemnt

accountname credit
X 300
Y 400


is there anyway i can join these two table like this, if so can someome tell me how to do it please.
accountname debit credit
A 100
B 200
X 300
Y 400

I have tried this sattement but it doesnot work
SELECT accountname, NULL AS debit, credit FROM revenue
UNION ALL
SELECT accountname, debit, NULL FROM expense

Recommended Answers

I have tried this sattement but it doesnot work
SELECT accountname, NULL AS debit, credit FROM revenue
UNION
SELECT accountname, debit, NULL FROM expense

This statement is fine. You should get the result. what error you are getting?

Jump to Post

All 2 Replies

I have tried this sattement but it doesnot work
SELECT accountname, NULL AS debit, credit FROM revenue
UNION
SELECT accountname, debit, NULL FROM expense

This statement is fine. You should get the result. what error you are getting?

Is there any column on which both the tables can be joined (account_id may be).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.