wrote query for inner joins on the tables