I have to combine data from 2 tables into a final result which will include columns from both tables. Both tables have 1 common column but its value may/may not have the same value.
So if a value from that common column exists in both tables then the value should be printed as it is but if a value exists in one table and not in another then for such NULL value should be printed.
Also please note, as the title of the post says, In real time scenario I will have to do this for n number of tables so it could be 2,3,4....
I tried joining the table based on a common column, but then I am not able to print all sf_id values of both tables also tried UNION but since not all columns are same between 2 tables so cannot make use of it.
Can someone please help me to understand how I can get the expected output?
Thanks.
Below is the sample scenario code:
CREATE TABLE test1
(
sf_id character varying(100),
acc_count bigint,
ver character varying(100)
);
CREATE TABLE test2
(
sf_id character varying(100),
cont_count bigint,
dis_count bigint
);
INSERT INTO test1 (sf_id,acc_count,ver) VALUES ('S1',5,'1.0.0'), ('S2',10, '9.8');
INSERT INTO test2 (sf_id,cont_count,dis_count) VALUES ('S1',100,50), ('S3',500,78);
SELECT * FROM test1;
SELECT * FROM test2;
DBFiddle for the same
Below is the expected output