I'm trying to merge 3 tables, namely history, history_value and hocvien to retrieve the columns, namely ['ngaybaoluu', 'ngayhoclai','lydo','hv_fullname','action', 'object', 'hv_coso']. The problem is that my python result come out with no value for the column ['ngaybaoluu']. I have tried the same inner join in SQL and get the desired result. Why is this the case? Please help me.
Python code (product result with no value for column ngaybaoluu)
# import necessary packages
from urllib.request import urlopen
import pandas as pd
import json
import requests
#Get a response and conver to json
req = requests.get('linktoAPI')
req_json = req.json()
# History_value table
df = pd.DataFrame(json.loads(r['history_value']) for r in req_json)
history_value = df[['ketoan_id', 'lop_id', 'lydo','hv_id', 'ngayhoclai', 'ngaybaoluu', 'huyhopdong', 'chinhanh' ]]
# History table
response = urlopen('https://office.ieltsvietop.vn/api/get_data/history')
history = pd.read_json(response)
# Hocvien table
response = urlopen('https://office.ieltsvietop.vn/api/get_data/hocvien')
data_json = json.loads(response.read())
hocvien = pd.DataFrame(data_json)
display(hocvien.columns)
# Merge history_value to history using (ketoan_id)
history_value_history = history_value.merge(history, on ='ketoan_id', how ='inner',suffixes =('_left', '_right'))
display(history_value_history.columns)
# Merge history_value_history to hocvien using (hv_id)
history_value_history_hocvien = history_value_history.merge(hocvien, left_on = 'hv_id_right', right_on ='hv_id', how = 'inner')
display(history_value_history_hocvien[['ngaybaoluu', 'ngayhoclai','lydo','hv_fullname','action', 'object', 'hv_coso']])
print('Success')
SQL code (produce desired results)
SELECT hv_fullname,ngaybaoluu, ngayhoclai, ketoan_id, hv_coso, action, object, lop_id
FROM history_value
join history using (ketoan_id)
join hocvien on hocvien.hv_id = history.hv_id