Write the SQL statement for the query : “ Find the name of the students whose…

2023

Write the SQL statement for the query : “ Find the name of the students whose name contains letter ‘D’ .

  1. A.

    Select name from student where name like ‘%D%’ ;

  2. B.

    Select name from student where name like ‘%D’ ;

  3. C.

    Select name from student where name like ‘D%’ ;

  4. D.

    none of the above

Attempted by 824 students.

Show answer & explanation

Correct answer: A

Ans A

Solution

Pattern matching can be performed on strings, using the operator like.

Percent (%): The % character matches any substring.

Underscore ( ): The character matches any character.

For example:

’D%’ matches any string beginning with “D”.

’%D%’ matches any string containing “D” as a substring.

’_ _ _’ matches any string of exactly three characters.

’_ _ _%’ matches any string of at least three characters

Explore the full course: Cognizant Preparation