0% found this document useful (0 votes)
12 views

SQLinsertInto Whereclause

The document discusses various SQL statements including SELECT, WHERE, INSERT, UPDATE and DELETE. SELECT is used to retrieve data, WHERE filters records, INSERT adds new records, UPDATE modifies existing records, and DELETE removes records.

Uploaded by

jayr domnigo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

SQLinsertInto Whereclause

The document discusses various SQL statements including SELECT, WHERE, INSERT, UPDATE and DELETE. SELECT is used to retrieve data, WHERE filters records, INSERT adds new records, UPDATE modifies existing records, and DELETE removes records.

Uploaded by

jayr domnigo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

The SQL SELECT DISTINCT Statement

The SELECT DISTINCT statement is used to return only distinct (different)


values.

Inside a table, a column often contains many duplicate values; and sometimes
you only want to list the different (distinct) values.

SELECT DISTINCT Syntax:

SELECT DISTINCT column1, column2, ...


FROM table_name;
Example:

SELECT DISTINCT name, adress


FROM person;
The SQL WHERE Clause
The WHERE clause is used to filter records.It is used to
extract only those records that fulfill a specified condition.

WHERE Syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition;

Example:
SELECT name, age
FROM person
WHERE where id =1;
Operators in The WHERE Clause
The following operators can be used in the WHERE clause:

Operator Description

= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal. Note: In some versions of SQL this operator may be
written as !=
BETWEEN Between a certain range
LIKE Search for a pattern
IN To specify multiple possible values for a column
SQL ALIASES
SQL ALIASES
SQL aliases are used to give a table, or a column in a table, a temporary name.

Aliases are often used to make column names more readable.

An alias only exists for the duration of that query.

An alias is created with the AS keyword.

Alias Column Syntax

SELECT column_name AS alias_name
FROM table_name;
SQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the selected column.

The MAX() function returns the largest value of the selected column.

MIN() Syntax MAX() Syntax


SELECT MIN(column_name) SELECT MAX(column_name)
FROM table_name FROM table_name
WHERE condition; WHERE condition;
SQL COUNT(), AVG() and SUM() Functions
COUNT() Syntax
The COUNT()
The COUNT() function returns the number of SELECT COUNT(column_name)
rows that matches a specified criterion. FROM table_name
WHERE condition;

The AVG() AVG() Syntax


The AVG() function returns the average value of a SELECT AVG(column_name)
numeric column. FROM table_name
WHERE condition;

The SUM() SUM() Syntax


The SUM() function returns the total sum of SELECT SUM(column_name)
a numeric column. FROM table_name
WHERE condition;
SQL IN Operator
The IN operator allows you to specify multiple values in a
WHERE clause.

The IN operator is a shorthand for multiple OR conditions.

IN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
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;
SQL ALIASES
SQL ALIASES
SQL ALIASES
The SQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a
table.

INSERT INTO Syntax


It is possible to write the INSERT INTO statement in two ways:

1. Specify both the column names and the values to be inserted:


INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Example:
INSERT INTO personTBL (id,name, age, address)
VALUES (123, “joel”, 26, “koronadal”);
2. If you are adding values for all the columns of the table, you do not need
to specify the column names in the SQL query. However, make sure the
order of the values is in the same order as the columns in the table. Here,
the INSERT INTO syntax would be as follows:

INSERT INTO table_name


VALUES (value1, value2, value3, ...);

Example:
INSERT INTO personTBL
VALUES (123, “joel”, 26, “koronadal”);
The SQL UPDATE Statement
The UPDATE statement is used to modify the existing
records in a table.

UPDATE Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

Example:
UPDATE person
SET name = “jay-r”, address = “banga”
WHERE id=1;
The SQL DELETE Statement
The DELETE statement is used to delete existing records in a
table.
DELETE Syntax:
DELETE FROM table_name WHERE condition;

Example:
DELETE FROM person WHERE id = 123;

You might also like