Monday 29 May 2017

DBMS LIKE clause ~ GNIITHELP

Like clause

Like clause is used as condition in SQL query. Like clause compares data with an expression using wildcard operators. It is used to find similar data from the table.

Wildcard operators

There are two wildcard operators that are used in like clause.
  • Percent sign % : represents zero, one or more than one character.
  • Underscore sign _ : represents only one character.

Example of LIKE clause

Consider the following Student table.
s_ids_Nameage
101Adam15
102Alex18
103Abhi17
SELECT * from Student where s_name like 'A%';
The above query will return all records where s_name starts with character 'A'.
s_ids_Nameage
101Adam15
102Alex18
103Abhi17

Example

SELECT * from Student where s_name like '_d%';
The above query will return all records from Student table where s_name contain 'd' as second character.
s_ids_Nameage
101Adam15

Example

SELECT * from Student where s_name like '%x';
The above query will return all records from Student table where s_name contain 'x' as last character.
s_ids_Nameage
102Alex18

No comments:

Post a Comment