SQL query from 2 tables before do another operation

SQL (firstly, query from 2 tables before do another operation)