You want to query the VARCHAR column ‘ code’ values that match:
• Start with “p”
• End with “_”
• Contain more than 3 characters
Assume that sql_mode is blank.
Which two queries select only those rows?
A.
SELECT code FROM operations WHERE code LIKE “p&&_”;
B.
SELECT code FROM operations WHERE code LIKE “ ’&’&_’ “ESCAPE “ ‘ ’’;
C.
SELECT code FROM operations WHERE code LIKE “p&_\_”;
D.
SELECT code FROM operations WHERE code LIKE “p_\&\_”;
E.
SELECT code FROM operations WHERE code LIKE “p_7_&;_”ESCAPE “/”;
Correct answers are A and C but only if the ampersand was replaced by a percentage sign !
I tried to create this and I just couldn’t, the information here is messed up plus me being a beginner it’s hard to see what I need to do. I suggest to read these link for more info.
https://dev.mysql.com/doc/refman/5.6/en/string-comparison-functions.html
https://dev.mysql.com/doc/refman/5.6/en/string-literals.html
http://www.w3resource.com/mysql/string-functions/mysql-like-function.php
It is C and D.
set sql_mode=”;
create table operations
(
`code` varchar(10)
);
insert into operations values
(‘pat’),(‘pete’),(‘peterson’),
(‘tim’),(‘timothy’),(‘Jay’),
(‘pl%m’),(‘pl_m’),(‘ple%’),
(‘ple_’),(‘pl%_’),(‘ple_%’);
SELECT code FROM operations WHERE code LIKE “p%%_”; #A, has the ability to grab less than 4 letters#
SELECT code FROM operations WHERE code LIKE “|%|%_’” ESCAPE “|”; #B, can only grab the specific phrase of %%_ #
SELECT code FROM operations WHERE code LIKE “p%_\_”; #C, works#
SELECT code FROM operations WHERE code LIKE “p_\%\_”; #D, works#
SELECT code FROM operations WHERE code LIKE “p_7_&;_” ESCAPE “|”; #E, No Idea on what they are asking for#
Actually it isn’t C!
add this to the list:
insert into operations values (‘pa_’); #C, won’t work now#
It’s D and most likely E.
more than 3 characters…
E works if this is statement:
SELECT code FROM operations WHERE code LIKE “p_|_%|_” ESCAPE “|”; #E#
OR
SELECT code FROM operations WHERE code LIKE “p_%_%|_” ESCAPE “|”; #E#
and this to the table:
insert into operations values (‘pa__’),(‘pa_dfds_’);
SELECT code FROM operations WHERE code LIKE “p_%_%|_” escape “|”;
SELECT code FROM operations WHERE code LIKE “p%__\_”;
C+E
SELECT code FROM operations WHERE code LIKE ‘p%_\_’;
SELECT code FROM operations WHERE code LIKE ‘p_%_%;_’ESCAPE ‘/’;
D,E
wildcat “&” mean zero to many