I am creating a new table with data from another table. I would like to combine the values from an Income_Ledger table as well as an Expenditure_Ledger table, with a WHERE condition, into a new table.
I can successfully add the values if only using one of the tables, but I can’t seem to write the SQL syntax to perform the input from both tables. i.e. the AS SELECT, FROM, WHERE works if only using one of the two tables.
Thanks for any help
MySQL (ver 14.14 Distr 5.7.23)
# bank in for below gives strings of: B1 and B2
for bank in Bank_Account_Code:
with engine.connect() as con:
con.execute('''
DROP TABLE IF EXISTS '''+bank+''';''')
con.execute('''
CREATE TABLE IF NOT EXISTS '''+bank+'''
AS SELECT id,Date,CR
FROM Income_Ledger
WHERE DR_code="'''+bank+'''"
AS SELECT id,Date,DR
FROM Expenditure_Ledger
WHERE CR_code="'''+bank+'''"
ORDER BY Date
;''')
