Sql Join Multiple Tables With Conditions