Day 8: I4G 10 Days Of Code Challenge

LeetCode Problem 175

I clicked on the link to the challenge and the first thing I saw was Combine two tables. I scanned through the problem and saw that it required an SQL solution.

I went through a crash course on SQL before finally taking a good look at the problem.

The Problem:

image 11.png

image 12.png

image 13.png

It's actually pretty easy to understand. It asks to create a program that combines the fields in 2 tables. The twist, however, is that not all fields in table A corresponds to the fields in table B. For such cases, the rest of the fields have an output of "null".

THOUGHT PROCESS

The entire problem can be solved by implementing a "LEFT JOIN" function with MySQL. The idea behind this is that the table A and its records are prioritised and all printed before the program begins to match each record with a corresponding field from table B.

Automatically, any record in table A without a corresponding field in table B will have "null" filled into those fieldnames.

According to the example, some fieldnames were rearranged, and I reflected this by calling them in the required order from the first table

The Solution:

image 14.png

Ciao!