3. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
4. Sql statements
• Query or command to perform a task in a
database
3 type
1. DDL
2. DML
3. DCL
16. Grant
Syntax in mysql
GRANT privilege_type ON table_name TO
‘user_name'@'localhost';
Example
GRANT select ON tbl_supplier TO
'john'@'localhost';
17. Revoke
Syntax in mysql
REVOKE privilege_type ON table_name FROM
‘user_name'@'localhost';
Example
REVOKE select ON tbl_supplier FROM
'suhail'@'localhost';
18. functions
• Built in function-perform calculation on data
1. Aggregate function
2. Scalar function
19. Aggregate function
• Return a single value for all the values in the
column after calculation
AVG()
Mysql syntax
Select avg(coulmn_name) from table_name;
Example
Select avg(int_salary) from employee;
COUNT(),FIRST(),LAST(),MAX(),MIN(),SUM()
20. Group by
• To group the result set by one or more column
• Often used in conjunction with aggregate
function
Syntax in mysql
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name;
Example
Select vchr_city,sum(mark) from tbl_student group by vchr_city;
21. Scalar function
• Return single value for each value in a column
UCASE()
Syntax in mysql
Select UCASE (column_name) from table_name;
Example
Select UCASE(first_name) from tbl_student;
• LCASE(),MID(),LEN(),ROUND(),NOW(),FORMAT()
22. Joins
• Used to combine rows from two or more
tables
Different joins
• inner join
• Left join
• Right join
23. Inner join
• Returns all rows when there is at least one
match in BOTH tables
Syntax in mysql
Select column_name(s) from table1 join table2 on
table1.column_name=table2.column_name;
24. Pk_int_dept_id Vchr_dept_name
1 CS
2 EC
3 EE
4 MECH
pk_int_class_id Vchr_class_name int_dept_id
1 CS100 1
2 CC300 5
3 EC100 2
4 MECH100 4
Example
select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from
tbl_dept join tbl_classes on tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
25. The result set will be
Vchr_department_
name
Vchr_class_name Pk_int_dept_id int_dept_id
CS CS100 1 1
EC EC100 2 2
MECH MECH100 4 4
26. Left join
• returns all rows from the left table (table1), with the matching
rows in the right table (table2).
• Syntax in mysql
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
27. Pk_int_dept_id Vchr_dept_name
1 CS
2 EC
3 EE
4 MECH
Pk_int_class_id Vchr_class_name int_dept_id
1 CS100 1
2 EC100 2
3 CC100 5
4 MECH100 4
select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from
tbl_dept LEFT join tbl_classes on
tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
28. The result will be
Vchr_dept_na
me
Vchr_class_na
me
Pk_int_dept_i
d
int_dept_id
CS CS100 1 1
EC EC100 2 2
EE NULL 3 NULL
MECH MECH100 4 4
29. Right join
• Return all rows from the right table, and the matched rows from the left
table
Syntax in mysql
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
30. Pk_int_dept_id Vchr_dept_name
1 CS
2 EC
3 EE
4 MECH
Pk_int_class_id Vchr_class_name int_dept_name
1 CS100 1
2 EC100 2
4 MECH100 4
select vchr_dept_name,vchr_class_name,pk_int_dept_id,int_dept_id from
tbl_dept RIGHT join tbl_classes on
tbl_dept.pk_int_dept_id=tbl_classes.int_dept_id;
31. The result will be
Vchr_dept_na
me
Vchr_class_na
me
Pk_int_dept_i
d
int_dept_id
CS CS100 1 1
EC EC100 2 2
MECH MECH100 4 4
NULL CC100 NULL 5
33. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
34. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
35. Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us