I have two tables which are data sources say A,B. I want to fetch data for 4 columns from these tables. The 4 columns are present in the both the tables. ‘A’ table may or may not have values for the one or all the 4 columns. But for sure B table has values for all of them. So if it is present in A i have to select from them or else i have select from B. Say Col1, Col2 are present in A and col3 and col4 are not in A table, then it should fetch col1, col2 from A and col 3, col4 from B table.
I am not good in SQL. Can someone help me with this? Hope my question is clear. If not please let me know
You can use a LEFT OUTER JOIN to find a matching in A if it exists. If a matching row does not exist, the row from B will still remain in the query. In cases where A has a NULL value for one of the columns, COALESCE() can be used to fall back on B’s value for that column.
I wasn’t clear from your question on which criteria you would like to use to match rows between A and B, but maybe a query like the following will help if you fill in that detail.