You’d need to look at using the Database Connector module from the Marketplace. This allows you to connect to external databases and run SQL queries against them.
https://docs.mendix.com/appstore/connectors/database-connector/
I hope this helps. Good luck!