KnowledgeBoat Logo

Informatics Practices

Mr. Shivaya is using a table 'COURSE' with the following columns: COURSE_ID, COURSE_NAME. He needs to display the names of all the courses which end with "SCIENCE". He has written the query mentioned below, which is not giving the desired result.

SELECT COURSE_ID, COURSE_NAME FROM COURSE WHERE COURSE_NAME = '_SCIENCE';

Help Mr. Shivaya to write the correct query.

Relational Database

3 Likes

Answer

SELECT COURSE_ID, COURSE_NAME FROM COURSE WHERE COURSE_NAME LIKE '%SCIENCE';
Explanation

The "=" operator is used for exact matching and the "_" wildcard character in SQL is used to match a single character, not a sequence of characters. To achieve the desired result, Mr. Shivaya should use the LIKE operator with the "%" wildcard character, which matches any sequence of characters.

Answered By

1 Like


Related Questions