Professional Documents
Culture Documents
MySQL Session 2
MySQL Session 2
Use mydb;
IN NOT IN
BETWEEN NOT BETWEEN
LIKE NOT LIKE
IS NULL IS NOT NULL
IN / NOT IN:
➢ It picks one by one value from the given list.
➢ It supports with all types of data.
Examples;
*Display employees whose id’s are 11,33 and 55;
select * from employee where id in(11,33,55);
Example:
select * from employee where id between 11 and 44;
select * from employee where id not between 11 and 44;
Examples:
*List the employees whose name starts with ‘S’
select * from employee where name like 'S%';
Examples:
Select all records where the value of the name column starts with
letter "a" and ends with the letter "b".
Name Usage
count Gives no. of rows in the given column
sum Gives total on the given column
avg Gives average of the given column
min Picks the smallest value from the given column.
max Picks the largest value from the given column
Example:
SELECT count(*), sum(sal), avg(sal), min(sal), max(sal) FROM employee;
Examples;
Example:
*Display sum of salaries of dept whose sum of salaries is more than 100000
SELECT dno, SUM(sal) FROM employee GROUP BY dno HAVING sum(sal) > 100000;
Examples:
SELECT *FROM employee ORDER BY sal;
SELECT *FROM employee ORDER BY name;
➢ In a sub query, first inner query is executed and based on the output of inner query, outer query
will be executed.
➢ Without sending multiple queries to the DB server to get the result, by using Sub Queries we can
send a single query to DB s/w to get response.
➢ Sub queries improve performance of the application while retreiving or manipulating data.
Examples;
*List the employs who belongs to 'Ganesh' dept. (without using sub query)
SELECT dno FROM employee WHERE name='Ganesh';
SELECT * FROM employee WHERE dno=20;
*List the employs who belongs to Rupesh dept. (using sub query)
SELECT * FROM employee WHERE dno=(SELECT dno FROM employee WHERE name='Ganesh');
Limit clause has two components, First component (n-1) is to skip number of rows from top and