You are on page 1of 3

Chapter-6 SQL Concepts

Data Manipulation Language:


It is used to retrieve or modify table data; it consists of four main SQL
statements:
SELECT, INSERT, UPDATE, DELETE

The SELECT statement: It is used for retrieves table data.


Syntax is-
SELECT * FROM <Table Name>

The INSERT statement:


It is used to add new rows to a table or view. Inserting a row into a
view also insert the row into the table on which the view is based.
Syntax is-
INSERT INTO<Table Name> (id, name, dept) VALUES (007,’blue’, 66)

The UPDATE statement:


It is used to change the data in a table or view. Updating a row in a
view updates a row in its base table. You can change the value of one or
more columns for each row that satisfies the conditions specified by a
WHERE clause.
Syntax is-
UPDATE <Table Name> (dept, name) = (54, Amisha) WHERE id = 315

The DELETE statement:


It is used to delete entire rows of data from a table or view. Deleting
a row from a view deletes the row from the table on which the view is based.
You can delete each row that satisfies the conditions specified by a WHERE
clause.
Syntax is-
DELETE FROM <Table Name>
OR
DELETE FROM <Table Name> WHERE id IN (315)

Removing duplicate Rows:


Use the DISTINCT clause to remove duplicate rows in a result set.
Syntax is-
SELECT DISTINCT <Table Name> <Row Title> FROM <Row Name> WHERE
<Table Name>
Using expressions to calculate values:
Use the AS clause to assign a meaningful name to an expressions or to
any item in the select list.
Syntax is-
SELECT <Table Name>, [expressions] FROM <Calculate> WHERE

Naming Expressions:
An Expression specifies a value. The value can be simple, such as a
constant or a column name without any operators, or it can be more complex
and include one or more different operator types. There are Sting
expressions, arithmetic expressions and case expressions.

1) String expression: The concatenation operator CONCAT links two


compatible string operands to from a string expression.
E.g. SELECT abc CONCAT ‘‘CONCAT xyz FROM <Table Name>

2) Arithmetic expression: It can be applied to numeric or date time


operands. Such like as [+, - , *, /].
E.g. SELECT <Rows Name>, <Value1> + <Value2> FROM <Table
Name>

3) Case expression: It can use case expression to specify a particular


result based on the evaluation of one or more conditions.
E.g. CASE <expression name> (parameter)
WHEN <string condition> THEN <String>
ELSE <sting condition>
END

Selecting data from more than one table (Join):


A join is query that combines data from two or more tables. If you
want a result set that contains attribute information about several related
entities, you need to construct a query that joins several related tables.
Syntax is-
SELECT * FROM <Table Name1> , <Table Name2>
Using a sub query column functions:
A query specifies a result table and is a component of certain SQL
statements. The three forms of a query are the fullselect, the subselect and
the SELECT clause.

Grouping:
Use the HAVING clause to retrieve results only for groups that satisfy
a specific condition. A HAVING clause can contain one or more predicated
that compare some property of the group with either another property of the
group.
e.g.
SELECT <DB Name>, SUM (row name) AS <total> FROM <Table Name>
GROUP BY <DB Name> HAVING SUM<Table Name>

The IN predicate:
It compares one or more values with a collection of values.
Syntax is-
SELECT * FROM <Table Name> WHERE <Row Name> IN (values)

The BETWEET predicate:


It compares a value with a range of values.
Syntax is-
<Compare Sting> BETWEEN <value> AND <value>

The LIKE predicates:


It can searches for strings that have a certain pattern. The pattern is
specified by a string in which the underscore ( _ ) character and the percent
sign ( % ) may have special meaning.
Syntax is-
SELECT <DB Name> FROM <Table Name> WHERE <string Name> LIKE
<Characters Name> ‘%’

The EXISTS predicate:


It can be tests for the existence of certain rows.
Syntax is-
SELECT ‘Yes!’ AS <Row Name> FROM <Table Name> WHERE EXISTS

The Quantified predicate:


It compares one or more values with a collection of values.
Syntax is-
SELECT <Column Name> FROM <String Name> WHERE <condition>

You might also like