A question answering system is the most promising way of retrieving data from the available knowledge base to the end-users to get the appropriate result for their questions. Many question answering systems convert the questions into triples which are mapped to the knowledge base from which the answer is derived. However, these triples do not express the semantic representation of the question, due to which the answers cannot be located. To handle this, a template-based approach is proposed that classifies the question types and finds appropriate SPARQL query template for each type including comparatives and superlatives. The SPARQL query built is executed in the DBpedia endpoint and results are obtained. Compared with other factoid question answering systems, the proposed approach has the potential to deal with a large number of question types, including comparatives and superlatives. Also, the experimental evaluations of the system performed on the QALD 8 dataset presents good performance and can help users to find answers to their questions.