In: Computer Science
Which of the following WHERE clauses could return the value “Ravnica” from the field SET?
Select one:
a.
WHERE SET = “Rav%”;
b.
WHERE SET LIKE “Rav_”;
c.
WHERE SET LIKE “%av”;
d.
WHERE SET LIKE “%R%i%”;
Answer: Option d(WHERE SET LIKE “%R%i%”;)
When we are matching with some pattern we will use the LIKE operator.
Option a(WHERE SET = “Rav%”;) should exactly expect the column SET value to be "Rav%". So, it is invalid in case of value to return "Ravnica".
Option b(WHERE SET LIKE “Rav_”;) should expect the column SET value to be four, Three letters starts with "Rav" and one more letter can be anything. In case of returning Ravnica record, we should have the value like "Rav____". Mentioning underscore can fill up anything into it but within number of underscore mentioned.
Option c(WHERE SET LIKE “%av”;) As like underscore, % also can fill up anything but the difference is it will not restrict with number of characters. % can fill upto maximum characters it can but the text should end up with av. As "Ravnica" is not ending with text "av" it is also not valid.
So, while considering the % Operator feature, WHERE SET LIKE “%R%i%”; will check for anything before and after filled with R & i and returns Ravnica.