In which file can i add custom sql complex queries to fetch data from another database table and how?

If i want to fetch data from one database table and display that data in my custom module using complex sql queries then in which file should i add sql query and how??

and also how can i make dropdown with values fetching from another database table using sql queries??

Parents Reply Children