Python - MySQL table join

null.ts :

Im trying to outer joins on multiple tables within a python query.

(outer join because some fields have null data)

Im using the following:

sql = "SELECT \
  CATINFO.Chip_ID AS Cat, \
  CATDIET.Diet_Req AS Diet, \
  CATMEDICAL.Med_his AS Med\
  FROM CATINFO \
  OUTER JOIN CATDIET, CATREQ, CATMEDICAL ON CATINFO.ID = CATDIET.Chip_ID, CATREQ.Chip_ID, CATMEDICAL.Chip_ID"

i get the following error output:

mysql.connector.errors.ProgrammingError: 1064 (42000):
'OUTER JOIN CATDIET, CATREQ, CATMEDICAL ON CATINFO.Chip_ID = CATDIET.Chip_ID, CATREQ.Chip_ID, CATMEDICAL.Chip_ID'

Im not sure exactly where ive gone wrong.

the idented table format should be like the following example:

Chip_ID   diet         req           med 
1         low carb     null          broken leg
2         null         belly rubs    null
null.ts :
sql = "SELECT \
  CATINFO.Chip_ID AS Cat, \
  CATDIET.Diet_Req AS Diet, \
  CATMEDICAL.Med_his AS Med, \
  CATREQ.Add_Req AS Req \
  FROM CATINFO \
  LEFT JOIN CATDIET ON CATINFO.Chip_ID = CATDIET.Chip_ID \
  LEFT JOIN CATMEDICAL ON CATINFO.Chip_ID = CATMEDICAL.Chip_ID \
  LEFT JOIN CATREQ ON CATINFO.Chip_ID = CATREQ.chip_ID "

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=386124&siteId=1