Like operator in Teradata with examples

Like Operator in Teradata

The Like operator is used for pattern matching in Teradata. It needs to specify in the WHERE clause to search the specific pattern in a column. There are two wildcards that used along with Like operator.

  • % – The percent character is represents zero,one, or multiple characters
  • _ – The underscore character is represents the single character.

Syntax of Like operator

We need to mention the column name that we want to match with the pattern. After the LIKE operator, we can specify the required pattern string for matching.

Example : Like operation in Teradata

Lets create the Food_Revenue table to show the use of LIKE operator in Teradata

Food Revenue table for Like operation in Teradata
Food Revenue table for Like operation in Teradata

In the table, we have one of the column as Food Name that contains all the food item names such as Pizza,Burger,Scilian Pizaa,Fried Chicken and so on.

Here we wants to calculate the revenue for Pizza which means that we need to sum the revenue of all the food items that contains Pizza.

  • Scilian Pizza
  • Pizza
  • Sushi Pizza

Lets write the query with Like operator to get the required result in Teradata

Output

Like operation example in Teradata
Like operation example in Teradata

Since we have put the pattern as ‘%Pizza%‘ in the Like operator, the select query returned all the records which has a sub string of Pizza as food name. From this result set, we can get the revenue of these items using SUM function.

Like operator with sum function in Teradata
Like operator with sum function in Teradata