How to add a couple more sqlite queries? to another table? There are other ways to optimize code for speed? with sqlite3.connect(r'db\test.sqlite') as conn: cursor = conn.cursor() cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") tables = cursor.fetchall() for table_name in tables: cursor.execute('SELECT "ID", "USER_NAME", "NICK_NAME" FROM "namedb" WHERE "USER_NAME" = ?',('%'+username+'%',)) rows = cursor.fetchmany(100) headers = [description[0] for description in cursor.description] if not rows: await update.message.reply_text("cansel") else: row_text = f"Test" for row in rows: row_text += "\n".join([f"\n\n[{table_name[0]}]"] + [f"[{headers}]: {cell}" for i, cell in enumerate(row)]) with open(f"{username}.txt", "w", encoding="utf-8") as f: f.write(row_text) with open(f"{username}.txt", "rb") as f: await update.message.reply_document(document=f) conn.commit() conn.close() return Continue reading...