LIKE, BETWEEN AND ALIAS

  • LIKE OPERATOR:

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

There are two wildcards often used in conjunction with the LIKE operator:

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

SYNTAX:

SELECT column1, column2, …
FROM table_name
WHERE columnN LIKE pattern;

EXAMPLE:

Select * from order_products1;

Select * from order_products1 where cust_name LIKE ‘S%’;

Below screen shot shows the customer name which starts with letter ’S’ .

Select * from order_products1;

Select * from order_products1 where cust_name LIKE ‘%a’;

Below screen shot shows that the name of a customer which ends with letter ‘a’.

select * from order_products1 where cust_name LIKE ‘%_____n’;

Below screen shot will show the customer name with alphabet ‘n’ after 5 characters.

select * from order_products1 where cust_name LIKE ‘%________d’;

Below screen shot will show the order name with alphabet ‘d’ after 8 characters.

select * from order_products1 where order_Pname LIKE ‘%H________’;

Below screen shot will show the order name which starts with alphabet ‘H’ and has total 9 characters.

  • BETWEEN OPERATOR:

The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.

The BETWEEN operator is inclusive: begin and end values are included.

SYNTAX

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

EXAMPLE:

Select * from order_products1;

select * from order_products1 where order_code  Between ‘103’ AND ‘108’;

select * from order_products1 where order_code Not Between ‘104’ AND ‘106’;

ALIAS (AS) OPERATOR:

Alias are used to give a table, or a column in a table, a temporary name. An alias only exists for the duration of that query. An alias is created with the AS keyword.

SYNTAX:

When aliases are used on column

SELECT column_name AS alias_name
FROM table_name;

EXAMPLE:

select * from order_products1;

select order_code as code,cust_name as cust from order_products1;

select order_name as name,item_cost as cost from order_products1;