Zend certified PHP/Magento developer

Magento 2 – Best way to query data from tables (select with multiple joins)

I’m learning about Collections, Repositories and DTO, and I’m still trying to figure out what’s the best way to query a table to fetch data. I also found that we can use MagentoFrameworkAppResourceConnection for direct SQL queries.

My question is:

Which way should I use for future projects, since my goal is to use table data to create APIs and also frontend pages? Is there a better way for each case?