w3resource
SQL exercises

SQL: Using where clause like, underscore, escape operators

SQL Wildcard & Special Operator : Exercise-12 with Solution

Write a SQL statement to find those rows from the table testtable which contain the escape character underscore ( _ ) in its column 'col1'.

Sample table: testtable


Sample Solution :

SELECT *
FROM testtable
WHERE col1 LIKE '%/_%' ESCAPE '/';

Output of the Query:

col1
A001/DJ-402\44_/100/2015
A001_\DJ-402\44_/100/2015
A001_DJ-402-2014-2015
A002_DJ-401-2014-2015
A001/DJ_401
A001/DJ_402\44
A001/DJ_402\44\2015
A001/DJ_402\45\2015%100
A001/DJ_402%45\2015/300

Explanation :

Syntax of using where clause like, underscore and escape operator

Pictorial presentation :

Result of using where clause like, underscore and escape operator

Query Visualization:

Duration:

Query visualization of Using where clause like, underscore, escape operators - Duration

Rows:

Query visualization of Using where clause like, underscore, escape operators - Rows

Cost:

Query visualization of Using where clause like, underscore, escape operators - Cost

 

Practice Online


Contribute your code and comments through Disqus.

Previous: Write a SQL statement to find those salesmen with all information whose name containing the 1st character is 'N' and the 4th character is 'l' and rests may be any character.
Next: Write a SQL statement to find those rows from the table testtable which does not contain the character underscore ( _ ) in its column 'col1'.

What is the difficulty level of this exercise?