You are on page 1of 6

Experiment 7 - To implement Different operators(LIKE, BETWEEN, IN, Wildcards);

The LIKE operator is used to match text string patterns. In terms of syntax structure, it fits into a boolean
expression just as an equals sign normally would.

Syntax of LIKE OPERATOR:


SELECT column_list FROM table_name
WHERE column_name LIKE ‘xxxxxx’;

The BETWEEN operator in SQL is used to select values within a given range.

Syntax of BETWEEN OPERATOR:


SELECT column_list FROM tablename
Where column_N BETWEEN value_1 AND value_2;

IN operator allows to easily test if the expression matches any value in the list of values. It is used to remove
the need for multiple OR conditions in SELECT, INSERT, UPDATE or DELETE. NOT IN is used to
exclude the rows in your list. Any kind of duplicate entry will be retained.

Syntax:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (list_of_values);

A wildcard character is used to substitute one or more characters in a string.

Syntax for underscore:


SELECT * FROM table_name
WHERE column_name LIKE '_xxx';

Syntax for percentage:


SELECT * FROM table_name
WHERE column_name LIKE ‘'%xxx%';
Experiment 8 - Introduction about the Concept of Grouping clauses GROUP BY, ORDER BY, HAVING.
Briefly explain these clauses with examples.

There are three various different types of clauses:


- GROUP BY
- ORDER BY
- HAVING

Each of these clauses is briefly explained below:


GROUP BY:
- SQL GROUP BY statement is used to arrange identical data into groups. The GROUP BY statement is used with the
SQL SELECT statement.

Syntax for GROUP BY:


SELECT column
FROM table_name
WHERE conditions
GROUP BY column
ORDER BY column

ORDER BY:
- The ORDER BY clause sorts the result-set in ascending or descending order.
- It sorts the records in ascending order by default. DESC keyword is used to sort the records in descending order.

Syntax for ORDER BY:


SELECT column1, column2
FROM table_name
WHERE condition
ORDER BY column1, column2... ASC|DESC;

HAVING:
- The HAVING clause is used to specify a search condition for a group or an aggregate.
- Having is used in a GROUP BY clause. If you are not using a GROUP BY clause then you can use the HAVING
function like a WHERE clause.

Syntax for HAVING:


SELECT column1, column2
FROM table_name
WHERE conditions
GROUP BY column1, column2
HAVING conditions
ORDER BY column1, column2;
Experiment 9 - To implement Joins(inner, outer, natural, equi join) and related example.

INNER JOIN:

In SQL, INNER JOIN selects records that have matching values in both tables as long as the condition is satisfied. It returns the
combination of all rows from both the tables where the condition satisfies.

Syntax:

SELECT table1.column1, table1.column2, table2.column1,....

FROM table1

INNER JOIN table2

ON table1.matching_column = table2.matching_column;

OUTER JOIN:

We use the SQL OUTER JOIN to match rows between tables. We might want to get match rows along with unmatched rows as well
from one or both of the tables. We have the following three types of SQL OUTER JOINS:

- SQL Full Outer Join

- SQL Left Outer Join

- SQL Right Outer Join

Syntax:

SELECT * FROM table1 t1 LEFT JOIN table2 t2 ON t1.colunm = t2.column

UNION SELECT * FROM table1 t1 RIGHT JOIN table2 t2 ON t1.colunm = t2.column

OR

SELECT * FROM table1 t1 FULL OUTER JOIN table2 t2 ON t1.colunm = t2.column

NATURAL JOIN:

Natural Join joins two tables based on the same attribute name and datatypes. The resulting table will contain all the attributes of
both the table but keep only one copy of each common column.

Syntax:

SELECT *

FROM table1 NATURAL JOIN table2;

EQUI JOIN:

An equijoin is an operation that combines multiple tables based on equality or matching column values in the associated tables.

Syntax:

SELECT (column_list | *)

FROM table_name1

JOIN table_name2

ON table_name1.column_name = table_name2.column_name;
Inner Join

Outer Join
Natural Join

Equi Join
Experiment 10 - Introduction of VIEW. How to create VIEW. Explain with an example.

A VIEW in SQL Server is like a virtual table that contains data from one or multiple tables. It does not hold
any data and does not exist physically in the database. Similar to a SQL table, the view name should be unique
in a database. A view also has rows and columns as they are in a real table in the database.

We can create a view by selecting fields from one or more tables present in the database. A View can either
have all the rows of a table or specific rows based on certain condition.

It contains a set of predefined SQL queries to fetch data from the database. It can contain database tables from
single or multiple databases as well.

A VIEW does not require any storage in a database because it does not exist physically. In a VIEW, we can
also control user security for accessing the data from the database tables. We can allow users to get the data
from the VIEW, and the user does not require permission for each table or column to fetch data.

Syntax:
CREATE VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE condition;

You might also like