2 Lines SQL & Pandas 🐼
Intuition\nWe want to combine information from two tables based on a common column (personId), the initial intuition is to use a join operation. \n\nSpecificall
# Intuition\nWe want to combine information from two tables based on a common column (personId), the initial intuition is to use a join operation. \n\nSpecifically, a left join will allow us to retain all records from the left table (person) and match them with corresponding records from the right table (address).\n\n---\n\n# Approach\nPerform a left join on the personId column between the person and address DataFrames using the merge function in pandas.\n\nSelect the desired columns (\'firstName\', \'lastName\', \'city\', \'state\') from the merged DataFrame to create the result DataFrame.\n\n# Complexity\n- Time complexity:\nThe merge operation complexity would be approximately O(n + m), as it involves creating an index and matching rows based on the personId column.\n\n- Space complexity:\nThe space complexity involves the memory required to store the merged DataFrame and the result DataFrame. \n\n# Code \n```SQL []\n# Write your MySQL query statement below\n\nSELECT p.firstName, p.lastName, a.city, a.state FROM Person p\nLEFT JOIN Address a ON p.personId = a.per\n```\n```Pandas []\nimport pandas as pd\n\ndef combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFrame:\n    merged_df = person.merge(address, on=\'personId\', how=\'left\')\n    result_df = merged_df[[\'firstName\', \'lastName\', \'city\', \'state\']]\n    return result_df\n```\n\n> \uD83D\uDCA1
['Database', 'MySQL', 'Pandas']