0% found this document useful (0 votes)
9 views3 pages

Learnsqlpart 4

The document discusses different SQL operators including IN, BETWEEN, LIKE, and HAVING. It provides syntax examples and usage scenarios for each operator to select or filter data in a table based on column values.

Uploaded by

dxxxksh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Learnsqlpart 4

The document discusses different SQL operators including IN, BETWEEN, LIKE, and HAVING. It provides syntax examples and usage scenarios for each operator to select or filter data in a table based on column values.

Uploaded by

dxxxksh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

IN Syntax

SELECT column_name(s)

FROM table_name

WHERE column_name IN (value1, value2, ...);

Find all customers that are located in "Germany", "France" or

"UK":

SELECT * FROM Customers

WHERE Country IN ('Germany', 'France', 'UK');

SELECT * FROM Customers

WHERE Country =’Germany’ or country=’France’ or

Country=’UK’;

The SQL 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.

BETWEEN Syntax

SELECT column_name(s)

FROM table_name

WHERE column_name BETWEEN value1 AND value2;

Find all products with a price BETWEEN 10 and 20:

SELECT * FROM Products

WHERE Price BETWEEN 10 AND 20;

SELECT * FROM Emp

WHERE Sal BETWEEN 10000 AND 25000;


The SQL 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 represents a single character

SELECT column1, column2, ...

FROM table_name

WHERE columnN LIKE pattern;

Find customers with a CustomerName starting with "a":

SELECT * FROM Customers

WHERE CustomerName LIKE '%a';

Fnd customers with a CustomerName that have "sri":

SELECT * FROM Customers

WHERE CustomerName LIKE %sri%;

1. Find all customers with a CustomerName

that have "s" in the second position:

Like ‘_s%’

3 Find employee names which starts with "a" and ends with

"o":

Like ‘a%o’

4 Find customers with a CustomerName that does NOT start

with "M":
Not like ‘M%’

The SQL HAVING Clause

The HAVING clause was added to SQL because the WHERE

keyword could not be used with aggregate functions.

HAVING Syntax

SELECT column_name(s)

FROM table_name

WHERE condition

GROUP BY column_name(s)

HAVING condition

ORDER BY column_name(s);

The following SQL statement lists the number of customers in each

country. Only include countries with more than 5 customers:

Example

SELECT COUNT(CustomerID), Countr

You might also like