I have thoroughly searched for a solution but couldn't find any. Issue is that I can run below query successfully in MySQL console while when I try to run it using Python it gives error. I'm able to run other sql queries using python but not this one.
Query -
qry = "UPDATE test.flight_track e,
(SELECT c.connection,COUNT(c.bag_seal_number) bag_count
FROM
(SELECT a.bag_seal_number, a.status_code, a.connection, a.scanned_datetime
FROM
livedata.livebag a
WHERE a.auto_incr IN (SELECT MAX(b.auto_incr) FROM livedata.livebag b
GROUP BY b.bag_seal_number)) c
WHERE c.status_code = 'In Transit'
GROUP BY c.connection) d
SET e.bag_count = d.bag_count
WHERE e.conn_id = d.connection"
cursor.execute(qry)
db.commit()
Error-
_mysql_exceptions.OperationalError: (1046, 'No database selected')