CodesJava

Easy learning with example program codes

LIKE condition in PostgreSQL

PostgreSQL LIKE
To filter the results, the PostgreSQL LIKE condition is used with a combination of WHERE Clause in SELECT, INSERT, UPDATE and DELETE statements to perform pattern matching.

Syntax:

WHERE expressions LIKE pattern [ ESCAPE 'escape_character' ]  

Parameters:
expressions: It is used to specify a column or a field.
pattern: It is used to specify the character expression for pattern matching.
escape_character: It is an optional parameter which is used to test for literal instances of a wildcard character such as % or _.

Example: Using wildcard: Percent(%).
Students table:

ID	NAME	AGE
1	Joy	5
2	Smiley	13
3	Happy	11
4	Tom	15
5	Jerry	10
6	Davison	6
7	David	8

Query:

SELECT “AGE”  
FROM “STUDENTS”  
WHERE “NAME” LIKE 'Dav%';

Output:

AGE
6
8

Example: Using wildcard: Underscore(_).
Students table:

ID	NAME	AGE
1	Joy	5
2	Smiley	13
3	Happy	11
4	Tom	15
5	Jerry	10
6	Davison	6
7	David	8

Query:

SELECT “AGE”  
FROM “STUDENTS”  
WHERE “NAME” LIKE 'Dav_son';

Output:

AGE
6
Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status