MySQL

adplus-dvertising
Like in MySQL
Previous Home Next

This clause is used for pattern searching string or characters in the specified condtions, they require some characters for searching, they are known as the Wildcard Characteres which provides a easier way to search any related string or character value from the requested column. They can be categories into two ways , they are

TypeDescription
%Minimum 1 size of characters
_size of One character

Syntax

SELECT *   
FROM tablename  
WHERE Clause 
LIKE 'type_define';

The % define the any number of characters in which lname starting letter is 's' and display the following result.

Example

SELECT *
FROM studinfo 
WHERE lname
LIKE 's%' ;

If we want to add some additional condition like sid>105 then we can compute them also

Example

SELECT *
FROM studinfo 
WHERE sid > 105 AND lname
LIKE 's%' ;

Suppose wo know only the first and last character of any stored value we can also search them using the below command

Example

SELECT *
FROM studinfo 
WHERE lname
LIKE 's%a' ;

In this first character is 's' and last character is 'a' and % define the undefined size of character stored in the specified conditions

Example

SELECT *
FROM studinfo 
WHERE lname LIKE 's%a'
ORDER BY sid ;

The underscore ( _ ) defines one character space of any type can be present which help them to search the requested query

Example

SELECT *
FROM studinfo 
WHERE lname LIKE 's_ _ _ _a';

The above code we have 4 unspecified character between s and a so we have to insert 4 underscore( _ ) to get the desired output

In the above code we can also insert the conditions like sid > 105 and order by fname whose code is given below.

Example

SELECT *
FROM studinfo 
WHERE sid >105 lname LIKE 's_ _ _ _a'
ORDER BY fname;
Previous Home Next