0% found this document useful (0 votes)
38 views7 pages

Date: / /: Logical Operation in Where Clause

There are three logical operators in SQL - AND, OR, and NOT. The OR operator returns rows where either condition is true, AND requires both conditions to be true, and NOT returns rows where the condition is false. Logical operators can be used in WHERE clauses to filter rows based on multiple conditions. Other SQL clauses like SELECT, BETWEEN, IN, IS NULL, LIKE, GROUP BY, HAVING, and JOINs can also filter and relate data across tables.

Uploaded by

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

Date: / /: Logical Operation in Where Clause

There are three logical operators in SQL - AND, OR, and NOT. The OR operator returns rows where either condition is true, AND requires both conditions to be true, and NOT returns rows where the condition is false. Logical operators can be used in WHERE clauses to filter rows based on multiple conditions. Other SQL clauses like SELECT, BETWEEN, IN, IS NULL, LIKE, GROUP BY, HAVING, and JOINs can also filter and relate data across tables.

Uploaded by

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

Date: \ \

 Logical operation in where clause:-


There are three logical operators manely, AND, OR and NOT. These operators compare two conditions at
a time to determine whether a row can be selected for output.

Logical Operation Description


OR For the row to be selected at least one of the conditions
must be true.
AND For the row to be selected all the specific conditions must
be true.
NOT For the row to be selected the specific conditions must be
false.

 ‘Or’ logical operation:-


If want find the mnames of students whose gender either male or female.

 ‘and’ logical operation;-


If want find the sname of the student between roll no 10 to 20.

8
Date: \ \

 ‘not’ logical operation;-


If want find the fname of the student who do not read in 1st semester.

 Use of multiple logical operator in sql statement:-


If want find the fname,sname of the student whoseroll no between 10

to 20 ,or those who not read in 1st semester.

 Sql comparison keywords:-

Comparison operators Description


LIKE Colum values are similar to specified character.
IN Colum values are equal to anyone of a specified set of
values.
BETWEEN-AND Colum value is between two values, including the end
values specified in the range.
IS NULL Colum value does not exist.

8
Date: \ \

 Sql ‘like’ operators:-


The LIKE operator is used to list all rows in a table whose column values match a specified
pattern. It is useful when the entire value is not known. For this purpose wildcard character ‘%’ is
used.
Example:
To select the student whose name sname we gins with ’a’.

The underscore character ‘_’ is used with LIKE operator. In search string, the underscore signifies a single character. For more than
one character two underscore can be used.

Example:
To select the student whose name sname with ’a’ second character..

8
Date: \ \
 Sql ‘in’ operators:-
The IN operator is used when want to compare a column with more than one value. It is similar to
an OR condition.
Example: To find the sname of the student whose dept_id either 2nd or 3rd.

 Sql ‘between…….and’ operators:-


The operation BETWEEN and AND ,are used to compare data for a range of values.
Example:

 Sql ‘is null’ operators:-


A column value is NULL if it does not exist. The IS NULL operator is used to display all the
rows for columns that do not have a values.
Example:

There would be no output if every student participate in a game in the stud_member,else the
names of the student who do not partipate in any games would be displayed.

 Sql group function:


Group functions are built in SQL function that operate on groups of rows and return one values
for the entire group.
These function are COUNT, MAX, MIN, AVG, SUM, DISTINCT.COUNT, MAX, MIN,
AVG,SUM are also called aggregate function.
 SQL count(*):
This function returns the number of rows in the table that satisfies the condition specified in the WHERE
condition. If the WHERE condition is not specified then the query returns the total number of rows in
table.
Example:

8
Date: \ \

 SQL distinct():
This function is used to select the distinct rows.
Example:

 Sql max():
This function is used to get the maximum values from acolumn drawn by an employe.
Example:

 Sql min():
This function is used to get the minimum value from column.
Example:

8
Date: \ \

 Sql avg():
This function is used to get the average values of a numeric column.
Example:

 Sql sum():
This function is used to get the sum of a numeric column.
Example:

 Sql group by clause:


The SQL GROUP BY CLAUSE is used along with the group functions.
To retrieve data grouped according to one or more columns.
Example:

8
Date: \ \

 Sql having clause:


Having clause is used to filter dta based on the group function.This is used with group function.
Example:

 Combining tables using joins:


SQL JOINS are used to relate information in different tables.A JOIN condition retrieves row
from two of more tables.

You might also like