SQL is a standard language used to create and manage relational database systems. It allows users to access and manipulate databases, including creating/modifying tables, inserting/deleting records, and running queries. Some key SQL elements include data types, literals, NULL values, and comments for documentation purposes. Common SQL commands include SELECT, INSERT, UPDATE, DELETE, and WHERE.
This document provides an overview of SQL and MySQL. It discusses that MySQL is an open source relational database management system that uses SQL. SQL allows users to create, access, and manage relational databases. The document then covers relational data models and terminology used in relational databases like tables, rows, columns, primary keys, and foreign keys. It also discusses SQL commands for data definition, manipulation, and control. Finally, it provides examples of SQL queries to retrieve, insert, update and structure data from tables in a MySQL database.
This document provides an overview of SQL (Structured Query Language) and how it can be used to access and manipulate data within relational database management systems (RDBMS). It describes what SQL is, common SQL commands like SELECT, INSERT, UPDATE and DELETE, SQL data types, database tables, and key clauses like WHERE that are used to filter SQL queries. Examples are provided throughout to illustrate SQL syntax and usage.
The document provides an introduction to the SQL language, including its main components of DML (Data Manipulation Language) and DDL (Data Definition Language). It discusses SQL concepts such as creating tables with data types, defining primary and foreign keys, and using basic queries with SELECT, FROM, WHERE and ORDER BY clauses.
SQL commands can be classified into DDL, DML, and DCL. DDL commands allow users to define and modify database schema by creating/deleting tables and imposing constraints. DML commands allow users to manipulate data by inserting, updating, deleting, and extracting data from tables. Common DDL commands include CREATE TABLE and ALTER TABLE. Common DML commands include SELECT, INSERT, UPDATE, and DELETE. SQL also supports pattern matching using wildcards like % and _ in the LIKE operator.
This document provides an overview of SQL and database concepts. It defines SQL as a standard language for accessing and manipulating databases and describes its basic functions like retrieving, inserting, updating and deleting data. It also explains key concepts like RDBMS, database tables, fields, records, data types, aggregation functions and constraints. Examples are given of SQL statements for creating databases and tables, inserting and selecting data, and setting primary keys, foreign keys and indexes.
This document discusses SQL and Oracle database concepts. It provides definitions of SQL, Oracle, and key Oracle data types. It also summarizes Oracle's object-relational capabilities and explains how to perform common data definition language (DDL) tasks like creating tables, adding constraints, and altering table structures in 3 sentences or less.
This document provides an overview of Oracle database including:
- Oracle is a powerful relational database management system (RDBMS) that allows sharing of data across multiple users through a centralized database server.
- It supports both relational and object-oriented features, making it an object-relational database management system (ORDBMS).
- SQL is the standard language used to access and manage data within an Oracle or other relational database.
This document contains information about a database management systems practical file submitted by Sachin for their fourth semester computer science course. It includes an index of experiments completed and sections covering database languages like DDL, DML, and DCL. It also discusses topics like data types in SQL, set operations, joins, query processing, and constraints.
Database management systems enable the storage of different data types in tables. MySQL supports numeric, string, and temporal data types. Numeric types include integers of various sizes for different value ranges and storage needs, floating-point types for approximate values, and fixed-point decimals for exact values. String types can be fixed-length or variable-length and include character and binary types. Temporal types store dates, times, or combined date-times. Each type has attributes that specify how MySQL handles values of that type.
The document provides information about Structured Query Language (SQL) including its basic concepts, data types, CREATE TABLE and INSERT commands, constraints, operators and data modifications. It defines key SQL concepts such as relations, attributes, tuples, primary keys, foreign keys and discusses SQL's capabilities for data definition, manipulation, queries and transaction control. Examples are given for creating a table and inserting records into the table.
The document provides an introduction to SQL and database concepts. It defines key terms like data, information, fields, records, databases, tuples, attributes, primary keys, and foreign keys. It also describes SQL commands for creating tables, inserting data, querying data using conditions, sorting results, and using aggregate functions. Common data types and constraints in SQL are explained. Functions for mathematical operations, string manipulation and date/time are also listed.
The document provides information about database concepts. It defines key terms like database, table, row, column, cell. It explains different data types like CHAR and VARCHAR. CHAR stores fixed length data while VARCHAR stores variable length data. The document also lists some commonly used database software and the difference between DBMS and RDBMS. It describes concepts like relationships, constraints, NULL values. It provides examples of different SQL statements.
The document provides an overview of SQL and reasons for learning SQL. It discusses what SQL is, why learn SQL, and provides an overview of SQL functions including retrieving data using SELECT statements, arithmetic expressions, null values, column aliases, concatenation operators, literal character strings, and alternative quote operators. It also covers restricting and sorting data using WHERE clauses, comparison operators, logical operators, pattern matching, and null conditions.
This document provides an overview of SQL and MySQL. SQL is a relational database management system originally developed by IBM. It allows users to connect to a database server and query or modify data. MySQL is a free, open-source SQL database. It provides more power and reliability than Microsoft Access. With SQL, the database resides on a server and users can connect via the web to access and edit data. phpMyAdmin provides a graphical interface for managing MySQL databases.
SQL is a standard language used to manage data in relational database systems. The SELECT statement is used to retrieve data from databases. It allows specifying columns, tables, filters and sorting. Common clauses include SELECT, FROM, WHERE, ORDER BY, and optional clauses like DISTINCT, GROUP BY and HAVING. Operators allow filtering rows by conditions, ranges, patterns and more. SQL is a non-procedural language used to perform queries, inserts, updates and deletes on a relational database.
Understanding P–N Junction Semiconductors: A Beginner’s GuideGS Virdi
Dive into the fundamentals of P–N junctions, the heart of every diode and semiconductor device. In this concise presentation, Dr. G.S. Virdi (Former Chief Scientist, CSIR-CEERI Pilani) covers:
What Is a P–N Junction? Learn how P-type and N-type materials join to create a diode.
Depletion Region & Biasing: See how forward and reverse bias shape the voltage–current behavior.
V–I Characteristics: Understand the curve that defines diode operation.
Real-World Uses: Discover common applications in rectifiers, signal clipping, and more.
Ideal for electronics students, hobbyists, and engineers seeking a clear, practical introduction to P–N junction semiconductors.
This document discusses SQL and Oracle database concepts. It provides definitions of SQL, Oracle, and key Oracle data types. It also summarizes Oracle's object-relational capabilities and explains how to perform common data definition language (DDL) tasks like creating tables, adding constraints, and altering table structures in 3 sentences or less.
This document provides an overview of Oracle database including:
- Oracle is a powerful relational database management system (RDBMS) that allows sharing of data across multiple users through a centralized database server.
- It supports both relational and object-oriented features, making it an object-relational database management system (ORDBMS).
- SQL is the standard language used to access and manage data within an Oracle or other relational database.
This document contains information about a database management systems practical file submitted by Sachin for their fourth semester computer science course. It includes an index of experiments completed and sections covering database languages like DDL, DML, and DCL. It also discusses topics like data types in SQL, set operations, joins, query processing, and constraints.
Database management systems enable the storage of different data types in tables. MySQL supports numeric, string, and temporal data types. Numeric types include integers of various sizes for different value ranges and storage needs, floating-point types for approximate values, and fixed-point decimals for exact values. String types can be fixed-length or variable-length and include character and binary types. Temporal types store dates, times, or combined date-times. Each type has attributes that specify how MySQL handles values of that type.
The document provides information about Structured Query Language (SQL) including its basic concepts, data types, CREATE TABLE and INSERT commands, constraints, operators and data modifications. It defines key SQL concepts such as relations, attributes, tuples, primary keys, foreign keys and discusses SQL's capabilities for data definition, manipulation, queries and transaction control. Examples are given for creating a table and inserting records into the table.
The document provides an introduction to SQL and database concepts. It defines key terms like data, information, fields, records, databases, tuples, attributes, primary keys, and foreign keys. It also describes SQL commands for creating tables, inserting data, querying data using conditions, sorting results, and using aggregate functions. Common data types and constraints in SQL are explained. Functions for mathematical operations, string manipulation and date/time are also listed.
The document provides information about database concepts. It defines key terms like database, table, row, column, cell. It explains different data types like CHAR and VARCHAR. CHAR stores fixed length data while VARCHAR stores variable length data. The document also lists some commonly used database software and the difference between DBMS and RDBMS. It describes concepts like relationships, constraints, NULL values. It provides examples of different SQL statements.
The document provides an overview of SQL and reasons for learning SQL. It discusses what SQL is, why learn SQL, and provides an overview of SQL functions including retrieving data using SELECT statements, arithmetic expressions, null values, column aliases, concatenation operators, literal character strings, and alternative quote operators. It also covers restricting and sorting data using WHERE clauses, comparison operators, logical operators, pattern matching, and null conditions.
This document provides an overview of SQL and MySQL. SQL is a relational database management system originally developed by IBM. It allows users to connect to a database server and query or modify data. MySQL is a free, open-source SQL database. It provides more power and reliability than Microsoft Access. With SQL, the database resides on a server and users can connect via the web to access and edit data. phpMyAdmin provides a graphical interface for managing MySQL databases.
SQL is a standard language used to manage data in relational database systems. The SELECT statement is used to retrieve data from databases. It allows specifying columns, tables, filters and sorting. Common clauses include SELECT, FROM, WHERE, ORDER BY, and optional clauses like DISTINCT, GROUP BY and HAVING. Operators allow filtering rows by conditions, ranges, patterns and more. SQL is a non-procedural language used to perform queries, inserts, updates and deletes on a relational database.
Understanding P–N Junction Semiconductors: A Beginner’s GuideGS Virdi
Dive into the fundamentals of P–N junctions, the heart of every diode and semiconductor device. In this concise presentation, Dr. G.S. Virdi (Former Chief Scientist, CSIR-CEERI Pilani) covers:
What Is a P–N Junction? Learn how P-type and N-type materials join to create a diode.
Depletion Region & Biasing: See how forward and reverse bias shape the voltage–current behavior.
V–I Characteristics: Understand the curve that defines diode operation.
Real-World Uses: Discover common applications in rectifiers, signal clipping, and more.
Ideal for electronics students, hobbyists, and engineers seeking a clear, practical introduction to P–N junction semiconductors.
GDGLSPGCOER - Git and GitHub Workshop.pptxazeenhodekar
This presentation covers the fundamentals of Git and version control in a practical, beginner-friendly way. Learn key commands, the Git data model, commit workflows, and how to collaborate effectively using Git — all explained with visuals, examples, and relatable humor.
Title: A Quick and Illustrated Guide to APA Style Referencing (7th Edition)
This visual and beginner-friendly guide simplifies the APA referencing style (7th edition) for academic writing. Designed especially for commerce students and research beginners, it includes:
✅ Real examples from original research papers
✅ Color-coded diagrams for clarity
✅ Key rules for in-text citation and reference list formatting
✅ Free citation tools like Mendeley & Zotero explained
Whether you're writing a college assignment, dissertation, or academic article, this guide will help you cite your sources correctly, confidently, and consistent.
Created by: Prof. Ishika Ghosh,
Faculty.
📩 For queries or feedback: [email protected]
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsesushreesangita003
what is pulse ?
Purpose
physiology and Regulation of pulse
Characteristics of pulse
factors affecting pulse
Sites of pulse
Alteration of pulse
for BSC Nursing 1st semester
for Gnm Nursing 1st year
Students .
vitalsign
Odoo Inventory Rules and Routes v17 - Odoo SlidesCeline George
Odoo's inventory management system is highly flexible and powerful, allowing businesses to efficiently manage their stock operations through the use of Rules and Routes.
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingCeline George
The Accounting module in Odoo 17 is a complete tool designed to manage all financial aspects of a business. Odoo offers a comprehensive set of tools for generating financial and tax reports, which are crucial for managing a company's finances and ensuring compliance with tax regulations.
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schoolsdogden2
Algebra 1 is often described as a “gateway” class, a pivotal moment that can shape the rest of a student’s K–12 education. Early access is key: successfully completing Algebra 1 in middle school allows students to complete advanced math and science coursework in high school, which research shows lead to higher wages and lower rates of unemployment in adulthood.
Learn how The Atlanta Public Schools is using their data to create a more equitable enrollment in middle school Algebra classes.
How to Manage Opening & Closing Controls in Odoo 17 POSCeline George
In Odoo 17 Point of Sale, the opening and closing controls are key for cash management. At the start of a shift, cashiers log in and enter the starting cash amount, marking the beginning of financial tracking. Throughout the shift, every transaction is recorded, creating an audit trail.
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...Celine George
Analytic accounts are used to track and manage financial transactions related to specific projects, departments, or business units. They provide detailed insights into costs and revenues at a granular level, independent of the main accounting system. This helps to better understand profitability, performance, and resource allocation, making it easier to make informed financial decisions and strategic planning.
The Pala kings were people-protectors. In fact, Gopal was elected to the throne only to end Matsya Nyaya. Bhagalpur Abhiledh states that Dharmapala imposed only fair taxes on the people. Rampala abolished the unjust taxes imposed by Bhima. The Pala rulers were lovers of learning. Vikramshila University was established by Dharmapala. He opened 50 other learning centers. A famous Buddhist scholar named Haribhadra was to be present in his court. Devpala appointed another Buddhist scholar named Veerdeva as the vice president of Nalanda Vihar. Among other scholars of this period, Sandhyakar Nandi, Chakrapani Dutta and Vajradatta are especially famous. Sandhyakar Nandi wrote the famous poem of this period 'Ramcharit'.
3. SQL – Structured Query Language
Is a language that enables you to create and operate
on relational databases
It is the standard language used by almost all
the database s/w vendors.
Pronounced as SEQUEL
Original version was developed by IBM’s
Almanden Research Center
Latest ISO standard of SQL was released in 2008 and
named as SQL:2008
4. SQL –features
Allows creating/modifying a database’s structure
Changing security settings for system
Permitting users for working on databases or tables
Querying database
Inserting/modifying/deleting the database contents
6. Literals
It means the fixed value or constant value. It may be of
character, numeric or date time type.
Character and date/time literals are always in single
quotation marks whereas numeric literals must be
without single quotation marks
For example – ‘Virat’, 12, 12.56, ‘04-20-2018’
format
Date and time values are always in
the YYYY-MM-DD HH:MI:SS
Special character like quotes are always written be
preceding it back-slash(). For example if we want to
store value as Tom’s Cat then it should be written as
Tom’s Cat
7. Data Type
Means the type of value and type of operation we
can perform on data. For example on numeric value
we can store numbers and perform all arithmetic
operations and so on.
MySQL support three categories of data types:
Numeric
Date and time
String types
8. Numeric Data Types
Data type Description
INT Numbers without decimal. Store up to 11 digits. -2147483648 to 2147483647
TINYINT Small integer value between 0 – 255 (4 digits)
SMALLINT More than TINYINT between -32768 to 32767 (5 digit)
MEDIUMINT Integer values up to 9 digits
BIGINT Very large integer value up to 11 digits
FLOAT(M,D) Real numbers i.e. number with decimal. M specify length of numeric value
including decimal place D and decimal symbol. For example if it is given as
FLOAT(8,2) then 5 integer value 1 decimal symbol and 2 digit after decimal
TOTAL – 8. it can work on 24 digits after decimal.
DOUBLE(M,D) Real numbers with more precision up to 53 place after decimal.
DECIMAL It is used to store exact numeric value that preserve exact precision for e.g.
money data in accounting system.
DECIMAL(P,D) means P no. of significant digits (1-65), D represent no. of digit
after decimal(0-30), for e.g DECIMAL(6,2) means 4 digit before decimal and 2
digit after decimal. Max will be 9999.99
9. Date and Time Types
Data type Description
DATE A date in YYY-MM-DD format between 1000-01-01 to 9999-12-31
In oracle data format is DD-MON-YYYY for e.g 10-SEP-2019
DATETIME Combination of date and time. For example to store 4th December
2018 and time is afternoon 3:30 then it should be written as –
2018-12-04 15:30:00
TIMESTAMP Similar to DATATIME but it is written without hyphen for example the
above date time is stored as 20181204153000
TIME To store time in the format HH:MM:SS
YEAR(M) To store only year part of data where M may be 2 or 4 i.e. year in 2
digit like 18 or 4 digit like 2018
10. String Types
Data type Description
CHAR(M) Fixed length string between 1 and 255. it always occupy M size for each data for
example if size is CHAR(20) and we store value ‘MOBILE’ , although the size of
MOBILE is 6 but in a table it will occupy 20 size with space padded at right side
for remaining place.
Mostly use in the case where the data to be insert is of fixed size like Grade
(A,B,C,..) or Employee code as E001, E002, etc. In this case CHAR will give better
performance than varchar
VARCHAR(M) Variable length string between 1 and 65535 (from MySQL 5.0.3) , earlier it was
255. it takes size as per the data entered for example with VARCHAR(20) if the
data entered is MOBILE then it will take only 6 byte. It is useful for the data like
name, address where the number of character to be enter is not fixed.
VARCHAR2 It is supported in ORACLE, both are almost same with minor difference. The
difference is in the way they are handling Empty String and NULL, for VARCHAR
these two are different where as VARCHAR2 treats both same.
11. Difference between
CHAR & VARCHAR
CHAR VARCHAR
Fixed length string Variable length string
Used where number of character to enter
is fixed like Grade, EmpCode, etc
Used where number of character to be
enter is not fixed like name, address etc.
Fast, no memory allocation every time Slow, as it take size according to data so
every time memory allocation is done
It takes more memory It takes less space
12. NULL VALUE
• NULL means missing information
• NULL can appear in any type of column if it is not restricted by
NOT NULL or PRIMARY KEY
• Always remember NULL is neither equal to 0 nor space. NULL
means nothing
• Used in situation like if email id is not available with students
then we will insert NULL
13. COMMENTS
• It is a text that is not executed, only for
documentation purpose. Comments in MySQL
can be written as
– Begin the comment with /* and */
– Begin the comment with – (followed by space)
– Begin then comment with #
• For example
– /* Select * from emp where empno=4 */
– Select * from emp; -- it will fetch all details
14. SQL COMMAND SYNTAX
Commands Description
Keywords That have special meaning in SQL. They are the commands in mysql
Clause They are used to support mysql commands like FROM, WHERE etc.
Arguments Values passed to clause like table name to FROM clause conditions to
WHERE clause for e.g.
SELECT * FROM EMP WHERE SALARY>12000;
In the above command
SELECT is keyword
FROM AND WHERE is clause
EMP is an argument to FROM
SALARY>12000 is argument
to WHERE
15. CREATING and USING DATABASE
CREATE DATABASE <DATABASE NAME>
CREATE DATABASE MYDB;
TO SEE LIST OF DATABASES:
SHOW DATABASES;
TO OPEN ANY DATABASE TO WORK
USE DATABASENAME;
USE MYDB;
17. Difference between Primary Key
and Unique Constraint
Primary Key Constraint Unique Constraint
There is only one Primary key There can be more than one
NULL values are not possible NULL values are possible
18. CREATING TABLE
datatype(size),
Syntax:-
Create Table TableName(ColumnName ColumnName
datatype(size),…..);
Example:-
Create Table Employee(empno int primary key, name
varchar(20), dept varchar(20), salary int);
Create table Student(roll int, name varchar(20),
stream varchar(20), per int);
19. CREATING TABLE
Create Table Employee(empno int primary key, name
varchar(20), dept varchar(20), salary int);
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
6 Krish HR
21. SHOWING TABLE STRUCTURE
TO SEE STRUCTURE OF TABLE:
It specifies the fields, data types and constraints used in the table.
DESC TABLENAME;
OR
DESCRIBE TABLENAME;
EXAMPLE:
DESC EMPLOYEE;
DESC STUDENT;
22. MySQL allows us to get the structure of table
like list of columns, data type, size and key
information of table using DESC / DESCRIBE
command
Example
23. INSERTING RECORDS IN TABLE
Syntax:-
Insert into tablename values(value1,value2,…)
Note:-
1) char, varchar and date value must be in single
quotes
2) Values must be passed in the order of their column
3) Date values are passed in the format
yyyy-mm-dd (in mysql)
24. INSERTING RECORDS IN TABLE
Syntax:-
Insert into emp values(1, ‘Ravi’,’Sales’,24000)
Insert into student values(1,’Mahi’,’Science’,89);
Inserting in selected columns
Insert into emp (empno, name, dept ) values
(2,’dipanker’,’IT’)
25. INSERTING RECORDS IN TABLE
Syntax:-
Insert into emp values(1, ‘Ravi’,’Sales’,24000);
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
6 Krish HR
26. SELECTING RECORD
Select statement allows to send queries to table and
fetch the desired record. Select can be used to select
both horizontal and vertical subset.
Syntax:-
Select * / columnnames FROM
tablename
[ where condition ];
27. SELECTING RECORD
Selecting all record and all columns
Select * from emp;
Selecting desired columns
select empno, name from emp;
Changing the order of columns
select dept, name from emp;
28. SELECTING RECORD
Selecting all record and all columns
Select * from emp;
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
6 Krish HR
30. ALL keyword
ALL keyword is used to see the duplicate records from output
For e.g. if we select dept from employee table it will display all the
department from the table including duplicate rows.
ALL is the default , so using it is optional.
Select ALL dept from emp;
Output will be:-
Dept
--------
Sale
Sale
IT
IT
HR
Empno Name Dept Salary
1 Ravi Sale 24000
2 Sunny Sale 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
31. DISTINCT keyword
DISTINCT keyword is used to eliminate the duplicate records from
output. If we don’t want to see the duplicate rows in output we
have to use DISTINCT keyword.
Select DISTINCT dept from emp;
Output will be:-
Dept
--------
Sale
IT
HR
Empno Name Dept Salary
1 Ravi Sale 24000
2 Sunny Sale 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
32. PERFORMING SIMPLE CALCULATION
While performing SQL operations sometimes simple
calculations are required, SQL provides facility to perform
simple arithmetic operations in query. In MySQL we can
give these queries without FROM clause i.e. table name
is not required for these queries,
For Example:
Select 10*2;
Select 10*3/6;
33. PERFORMING SIMPLE CALCULATION
MySQL also provides DUAL table to provide compatibility with
other DBMS. It is dummy table used for these type queries where
table name is not required. It contains one row and one column.
For example:
Select 100+200 from DUAL;
Select curdate( ) from dual;
CALCULATION WITH TABLE DATA
Select name, salary, salary * 12 Annual_Salary from emp;
Select empno, salary+1000 from emp;
Update student set total=phy+chem+maths+cs+eng;
34. COLUMN ALIAS
It is a temporary name/label given to column that will appear in
output. For example if column name is dept and you want
Department to appear as column heading then we have to give
Column Alias. If we want alias name of multiple words then it
should be enclosed in double quotes. Its format is :
ColumnName [AS] ColumnAlias
Example
(i)Select empno Employee_Number, name, dept Department,
Salary Income from emp;
(ii) Select name, Salary*12 as “Annual Income” from emp;
36. PUTTING TEXT IN QUERY OUTPUT
SQL allows to put user defined symbols or text with table output.
Like ‘Rs’ with Salary or ‘%’ symbol with commission
For e.g.
Select name, dept, ‘Rs.’, salary from emp;
Select name, ‘ works in department’, dept, ‘ and getting salary rs.
‘, salary from emp;
Select name, concat(‘Rs. ‘, salary) from emp;
37. WHERE clause
WHERE clause is used to select specified rows.
It allows to select only desired rows by applying condition.
We can use all comparison(>, <, >=, <=, =, <>) and logical
operator (AND, OR, NOT).
AND ( &&), OR (||) , NOT (!)
For example
Select * from emp where salary>4000;
Select * from emp where empno=1;
Select name,dept from emp where
dept=‘HR’;
39. WHERE clause
AND(&&) means both conditions must be true, OR(||) means
any condition must be true to produce output. NOT(!) will do
the reverse checking.
Select * from emp where salary>4000 and salary<8000;
Select * from emp where dept=‘Sales’ and salary<30000;
Select name,dept from emp where dept=‘HR’ and
salary>=20000 and salary<=40000;
Select * from emp where dept=‘HR’ or dept=‘IT’;
Select * from emp where NOT empno=4;
40. WHERE clause
Select * from emp where dept=‘Sale’ and salary<30000;
Empno Name Dept Salary
1 Ravi Sale 24000
42. BETWEEN
BETWEEN allows to specify range of values to search in any column. It
is used with AND clause and it will include the specified values during
the searching.
For e.g.
Select * from emp where salary between 18000 and 30000; Select
name from emp where empno between 2 and 5;
Select * from emp where salary NOT between 25000 and 35000;
43. BETWEEN
Select * from emp where salary between 18000 and 30000;
OR
Select * from emp where salary >= 18000 AND salary <= 30000;
Empno Name Dept Salary
1 Ravi Sale 24000
3 Shobit IT 30000
4 Vikram IT 27000
44. IN
IN allows to specify LIST of values in which searching will be
performed. It will return all those record that matches any
value in a given list of values. It can be thought as an
alternative of multiple ORs
Select * from emp where dept IN(‘sales’,’it’);
Select name from emp where empno IN (2,4,5); Select *
from emp where dept NOT IN(‘sales’,’it’)
45. IN
Select * from emp where dept IN(‘sales’,’it’);
OR
Select * from emp where dept =‘sales’ OR dept=’it’;
Empno Name Dept Salary
1 Ravi Sale 24000
2 Sunny Sale 35000
3 Shobit IT 30000
4 Vikram IT 27000
46. LIKE
LIKE allows to search based on pattern. It is used when
we don’t want to search an exact value or we don’t know
that exact value, and we know only the pattern of value
like name starting from any particular letter, or ending
with and containing any particular letter or word.
LIKE is used with two wildcard characters:
a) % : used when we want to substitute
multiple characters. With % length is not fixed.
b) _ (underscore) : used when we want to
substitute Single character.
47. LIKE
Search for employee whose name begins from ‘S’
Select * from emp where name like ‘S%’;
Search for employee whose name ends with ‘r’
Select * from emp where name like ‘%r’;
Search for employee whose name contains ‘a’ anywhere
Select * from emp where name like ‘%a%’
Search for employee whose dob is in feb(dd-mm-yy)
Select * from emp where dob like ‘%-02-%’
Search employee whose name is of 5 letters begins from ‘s’
Select * from emp where name like ‘s_ _ _ _ ’;
48. LIKE
Search for employee whose name begins from ‘s’
Select * from emp where name like ‘S%’;
Empno Name Dept Salary
2 Sunny Sale 35000
3 Shobit IT 30000
49. IS NULL
IS NULL is used to compare NULL values present in any
column. Because NULL is not considered as value so we
cannot compare with = sign, so to compare with NULL , SQL
provides IS NULL.
Select * from emp where salary is null; Select
* from emp where salary is not null;
50. SORTING OUTPUT
By default records will come in the output in the same order
in which it was entered. To see the output rows in sorted or
arranged in ascending or descending order ,SQL provide
ORDER BY clause.
By default output will be ascending order(ASC) to see output
in descending order we use DESC clause with ORDER BY.
Select * from emp order by name; (ascending order)
Select * from emp order by salary desc; (descending
order)
Select * from emp order by dept asc, salary desc;
51. SORTING OUTPUT
Select * from emp order by salary desc;
Empno Name Dept Salary
5 nitin HR 45000
2 Sunny Sale 35000
3 Shobit IT 30000
4 Vikram IT 27000
1 Ravi Sale 24000
52. JUST A MINUTE…
• Create the following table and add the records
in ITEMS table:
ItemNo Item Dcode Qty UnitPrice StockDate
5005 Ball Pen 0.5 102 100 16 2018-03-10
5003 Ball Pen 0.25 102 150 20 2017-05-17
5002 Gel Pen Premium 101 125 14 2018-04-20
5006 Gel Pen Classic 101 200 22 2018-10-08
5001 Eraser Small 102 210 5 2018-03-11
5004 Eraser Big 102 60 10 2017-11-18
5009 Sharpener Classic NULL 160 8 2017-06-12
53. JUST A MINUTE…
Write down the following queries based on the given table:
1) Select all record of table
2) Select ItemNo, name and Unitprice
3) Select all item record where Unitprice is more than 20
4) Select Item name of those items which are quantity
between 100-200
5) Select all record of Items which contains ‘pen‘ word in it
6) Select unique dcode of all items
7) Display all record in the descending order of UnitPrice
54. OPERATOR PRECEDENCE
When multiple operators are used in expression, then
evaluation of expression takes place in the order of
precedence. Higher precedence operator will execute
first. !
*, /, DIV, %, MOD
- +
<, >
==, >=, <=, !=, IS, LIKE, IN, BETWEEN
NOT
AND
OR
HIGH
LOW
55. AGGREGATE functions
Aggregate function is used to perform calculation on group of rows
and return the calculated summary like sum of salary, average of
salary etc.
Available aggregate functions are –
1. SUM()
2. AVG()
3. COUNT()
4. MAX()
5. MIN()
6. COUNT(*)
56. AGGREGATE functions
Select SUM(salary) from emp;
Output – 161000
Select SUM(salary) from emp where dept=‘sales’;
Output - 59000
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
57. AGGREGATE functions
Select AVG(salary) from emp;
Output – 32200
Select AVG(salary) from emp where dept=‘sales’;
Output - 29500
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
58. AGGREGATE functions
Select COUNT(name) from emp;
Output – 5
Select COUNT(salary) from emp where dept=‘HR’;
Output - 1
Select COUNT(DISTINCT dept) from emp;
Output - 3
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
59. AGGREGATE functions
Select MAX(Salary) from emp;
Output – 45000
Select MAX(salary) from emp where dept=‘Sales’;
Output - 35000
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
60. AGGREGATE functions
Select MIN(Salary) from emp;
Output – 24000
Select MIN(salary) from emp where dept=‘IT’;
Output - 27000
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
61. AGGREGATE functions
Select COUNT(*) from emp;
Output – 6
Select COUNT(salary) from emp;
Output - 5
Empno Name Dept Salary
1 Ravi Sales 24000
2 Sunny Sales 35000
3 Shobit IT 30000
4 Vikram IT 27000
5 nitin HR 45000
6 Krish HR
62. count(*) Vs count()
Count(*) function is used to count the number of rows in query
output whereas count() is used to count values present in any
column excluding NULL values.
Note:
All aggregate function ignores the NULL values.
Give previous example.
63. GROUP BY
GROUP BY clause is used to divide the table into logical groups and
we can perform aggregate functions in those groups. In this case
aggregate function will return output for each group. For example
if we want sum of salary of each department we have to divide
table records.
64. Aggregate functions by default takes the entire table as a single group that’s why
we are getting the sum(), avg(), etc output for the entire table. Now suppose
organization wants the sum() of all the job separately, or wants to find the average
salary of every job. In this case we have to logically divide our table into groups
based on job, so that every group will be passed to aggregate function for
calculation and aggregate function will return the result for every group.
65. column value. In those logically divided records we can
apply aggregate functions.
For. E.g.
SELECT SUM(SAL) FROM EMP GROUP BY DEPT; SELECT
JOB,SUM(SAL) FROM EMP GROUP BY DEPT; SELECT
JOB,SUM(SAL),AVG(SAL),MAX(SAL),COUNT(*)
EMPLOYEE_COUNT FROM EMP;
NOTE :- when we are using GROUP BY we can use only aggregate function and the
column on which we are grouping in the SELECT list because they will form a group other
than any column will gives you an error because they will be not the part of the group.
For e.g.
SELECT ENAME,JOB,SUM(SAL) FROM EMP GROUP BY JOB;
Error -> because Ename is not a group expression
Group by clause helps up to divide the table into logical groups based
66. HAVING with GROUP BY
• If we want to filter or restrict some rows from the output produced by
GROUP BY then we use HAVING clause. It is used to put condition of group of
rows. With having clause we can use aggregate functions also.
• WHERE is used before the GROUP BY. With WHERE we cannot use aggregate
function.
• E.g.
• SELECT DEPT,AVG(SAL) FROM EMP GROUP BY DEPT HAVING
DEPT IN (‘HR’,’SALES’)
• SELECT DEPT,MAX(SAL),MIN(SAL),COUNT(*) FROM EMP
GROUP BY DEPT HAVING COUNT(*)>1
• SELECT DEPT,MAX(SAL),MIN(SAL) FROM EMP WHERE
SAL>=2000 GROUP BY DEPT HAVING DEPT IN(‘IT’,’HR’)
67. JUST A MINUTE…
• Create the following table and add the records
ItemNo Item Dcode Qty UnitPrice StockDate
5005 Ball Pen 0.5 102 100 16 2018-03-10
5003 Ball Pen 0.25 102 150 20 2017-05-17
5002 Gel Pen Premium 101 125 14 2018-04-20
5006 Gel Pen Classic 101 200 22 2018-10-08
5001 Eraser Small 102 210 5 2018-03-11
5004 Eraser Big 102 60 10 2017-11-18
5009 Sharpener Classic NULL 160 8 2017-06-12
68. JUST A MINUTE…
Write down the following queries based on the given table:
1. Change the unitprice to 20 for itemno 5005
2. Delete the record of itemno 5001
3. Display all the item name in capital letters
4. Display first 4 character of every item name
5. Display all record whose dcode is not assigned
6. Display all items which are stocked in the month of
March
69. MYSQL FUNCTIONS
A function is built – in code for specific purpose that
takes value and returns a single value. Values passed to
functions are known as arguments/parameters.
There are various categories of function in MySQL:-
1) String Function
2) Mathematical function
3) Date and time function
70. String Function
Function Description Example
ASCII( ) Returns the ASCII
value of the
character
Select ascii(‘A’);
Output- 65
CHAR( ) Return character
for given ASCII
Code
Select char(65);
Output- A
CONCAT( ) Return concatenated
string
Select concat(name, ‘ works in ‘, dept,’
department);
LOWER()/
LCASE( )
Return string in
small letters
Select lower(‘INDIA’); Output- india
Select lower(name) from emp;
SUBSTRING(
S,P,N) /
MID(S,P,N)
Return N character
of string S,
beginning from P
Select SUBSTRING(‘LAPTOP’,3,3);
Output – PTO
Select SUBSTR(‘COMPUTER’,4,3);
Output – PUT
UPPER()/
UCASE( )
Return string in
capital letters
Select Upper(‘india’); Output- INDIA
LTRIM( ) Removes leading space Select LTRIM(‘Apple’); Output- ‘Apple’
71. String Function
Function Description Example
TRIM() Remove spaces from
beginning and ending
Select TRIM(‘ Apple ‘); Output-’Apple’
Select * from emp where trim(name) = ‘Suyash’;
INSTR() It search one string in
another string and
returns position, if not
found 0
Select INSTR(‘COMPUTER’,’PUT’); Output-4
Select INSTR(‘PYTHON’,’C++’); Output – 0
LENGTH() Returns number of
character in string
Select length(‘python’); Output- 7
Select name, length(name) from emp
LEFT(S,N) Return N characters of
S from beginning
Select LEFT(‘KV OEF’,2); Output- KV
RIGHT(S,N) Return N characters of
S from ending
Select RIGHT(‘KV OEF’,3); Output- OEF
72. Numeric Function
Function Description Example
MOD(M,N) Return remainder M/N Select MOD(11,5); Output- 1
POWER(B,P) Return B to power P Select POWER(2,5); Output-32
ROUND(N,D) Return number rounded to
D place after decimal
Select ROUND(11.589,2);
Output- 11.59
Select ROUND(12.999,2);
Output- 13.00
SIGN(N) Return -1 for –ve number 1 for
+ve number
Select sign(-10);
Output : -1
Select sign(10);
Output : 1
SQRT(N) Returns square root of N Select SQRT(144); Output: 12
TRUNCATE(
M,N)
Return number upto N place
after decimal without
rounding it
Select Truncate(15.789,2);
Output: 15.79
73. Date and Time Function
VINOD
KUMAR
VERMA,
PGT(CS),
KV
OEF
KANPUR
&
SACHIN
BHARDWAJ,
PGT(CS),
KV
NO.1
TEZPUR
Function Description Example
CURDATE( )/
CURRENT_DATE( )
/ CURRENT_DATE
Return the current date Select curdate(); Select
current_date();
DATE() Return date part from date- time
expression
Select date(‘2018-08-15 12:30’);
Output: 2018-08-15
MONTH() Return month from date Select month(‘2018-08-15’); Output: 08
YEAR() Return year from date Select year(‘2018-08-15’); Output: 2018
DAYNAME() Return weekday name Select dayname(‘2018-12-04’);
Output: Tuesday
DAYOFMONTH() Return value from 1-31 Select dayofmonth(‘2018-08-15’)
Output: 15
DAYOFWEEK() Return weekday index, for
Sunday-1, Monday-2, ..
Select dayofweek(‘2018-12-04’);
Output: 3
DAYOFYEAR() Return value from 1-366 Select dayofyear(‘2018-02-10’)
Output: 41
74. Date and Time Function
Function Description Example
NOW() Return both current date
and time at which the
function executes
Select now();
SYSDATE() Return both current date
and time
Select sysdate()
Difference Between NOW() and SYSDATE() :
NOW() function return the date and time at which function was executed
even if we execute multiple NOW() function with select. whereas SYSDATE()
will always return date and time at which each SYDATE() function started
execution. For example.
mysql> Select now(), sleep(2), now();
Output: 2018-12-04 10:26:20, 0, 2018-12-04 10:26:20
mysql> Select sysdate(), sleep(2), sysdate();
Output: 2018-12-04 10:27:08, 0, 2018-12-04 10:27:10
75. Class Assignment- PRACTICAL FILE
Write SQL queries for I to vi and outputs for vii to ix.
TABLE: VEHICLE
VCODE VEHICLETYPE PERKM
V01 VOLVO BUS 150
V02 AC DELUXE BUS 125
V03 ORDINARY BUS 80
V05 SUV 30
V04 CAR 18
TABLE: TRAVEL
CNO CNAME TRAVELDATE KM
VCODE NOP
101 K.Niwal 2015-12-13 200
V01 32
103 Fredrick Sym 2016-03-21 120
V03 45
105 Hitesh Jain 2016-04-23 450
V02 42
102 Ravi anish 2016-01-13 80
V02 40
107 John Malina 2015-02-10 65
V04 2
76. 1.To display CNO, CNAME, TRAVELDATE from the table TRAVEL in
descending order of CNO.
2. To display the CNAME in uppercase of all the customers from
the table TRAVEL who are travelling by vehicle with code V01 or
V02.
3.To display the CNO and CNAME , month and Year of TRAVEL for
all those who travelled between ‘2015-12-31’ and ‘2015-05-01’.
4. To add a new column status char(1) to the VEHICLE table.
5. To enter the value as ‘A’ for all Status values.
6. Delete Vehicletype CAR from Vehicle table.
7.SELECT Left(VEHICLETYPE,1) FROM VEHICLE;
8. SELECT A.VCODE,CNAME,VEHICLETYPE FROM TRAVEL A,VEHICLE
B WHERE A.VCODE=B.VCODE AND PERKM<90;
9. SELECT CNAME,KM*PERKM FROM TRAVEL A, VEHICLE B WHERE
A.VCODE=B.VCODE AND A.VCODE=‘V05’;
80. EXPORTING DATABASE
• Exporting means creating the text file containing all the
database contents which can be imported to any other
computer. We use mysqldump command for this purpose.
To export:
• Open cmd from Start button
Or
• Press Window Key + R and type cmd and press Enter
• Atcmd prompt like C:....> type mysqldump
command
81. EXPORTING DATABASE
• To export all database
– mysqldump --all-databases > c:mydb.sql
• It will create mydb.sql in C:, we can check it by open it.
• To export single database
– mysqldump myworks > c:mydb2.sql
• To export multiple datbase
– mysqldump myworks company c:mydb3.sql
83. IMPORTING DATABASE
• STEP – 1
– Save this file with mydb.sql or any name, in your
desired location for e.g. C:
• STEP – 2
– Open MySQL and type
• SOURCE C:mydb.sql
– It will create database myworks, 2 tables emp,
students with records. We can check it by “SHOW
TABLES” or “SELECT” command