SELECT *
FROM product_stocks
WHERE detected_date = (
SELECT MAX(detected_date)
FROM product_stocks
WHERE id = 18865
)
AND id = 18865;
Having lots of trouble converting this to SQLAlchemy query string. What's the most efficient way?
You can use from_statement
to execute the raw SQL-Query and fetch it in a SQL-Alchemy Object. This helps when it's easier to write plain SQL then SQLAlchemy Syntax.
Session.query(YourClass).from_statement(text('''SELECT * FROM product_stocks
WHERE detected_date = (SELECT MAX(detected_date) FROM product_stocks WHERE id = 18865)
AND id = 18865;''')).all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With