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

Mysql

Uploaded by

patilsiddeshb16
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Mysql

Uploaded by

patilsiddeshb16
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

SQL

It is stands for the structured Query language, it is used to interact with the database for
inserting, retriving , updating the data from the database. Basically it used to manuplate the
database.
MySQL:
It is the relational database management system (RDBMS), A software that enables users
to create, manage, and manipulate databases.
SQL is a language used to communicate with databases, while MySQL is a specific software
system used to implement and manage databases.

1|Page
2|Page
Creating the table:

3|Page
Inserting into table:

DQL/DRL data query language/ data retrieval language

WHERE & BETWEEN

IN => Used to reduced the


multiple or statement

4|Page
It select entities in column with value is null

WILDCARDS
• A wildcard character is used to substitute one or more characters in a string.
• Wildcard characters are used with the SQL LIKE operator.
• The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

ORDER BY:

DISTINCT:

5|Page
GROUP BY: this keyword is always used with the aggregate function

in SQL, we use the GROUP BY clause to group rows based on the value of columns.

Example: GROUP BY Number of Customers in Each Country

Here, the SQL command groups the rows by


the country column and counts the number
of each country (because of
the COUNT() function).

Note: The GROUP BY clause is used in conjunction with aggregate functions such as MIN() and
MAX(), SUM() and AVG(), COUNT(), etc.

6|Page
Having:

The SQL HAVING clause is used if we need to filter the result set based on aggregate functions such

as MIN() and MAX(), SUM() and AVG(), and COUNT().


Example

-- select customers with the same first name based on their age count
SELECT COUNT(age) AS Count, first_name
FROM Customers
GROUP BY first_name
HAVING COUNT(age) > 1;

Here, the SQL command

 counts the age of each row and groups them

by first_name

 returns the result set if the count of age is greater

than 1 (thus filtering out customers with the


the WHERE clause does not support aggregate functions.
same first_name)
Also, GROUP BY must be used before
the HAVING clause. To learn more, visit SQL GROUP
7|Page BY.
DDL: data definition language:

SQL Constraints
In a database table, we can add rules to a column known as constraints. These rules control the data that

can be stored in a column.

For example, if a column has NOT NULL constraint, it means the column cannot store NULL values.

The constraints used in SQL are:

Note: These constraints are also called integrity constraints.

8|Page
9|Page
10 | P a g e
SQL ALTER TABLE Statement

In SQL, the ALTER TABLE command is used to modify the structure of an existing table like adding,

deleting, renaming columns, etc.


Example

-- add phone column to Customers table


ALTER TABLE Customers
ADD phone varchar(10);

Here, the SQL command adds a column named phone to the Customers table.

11 | P a g e
DML: data modification language
DML (Data Manipulation Language) are SQL commands focused on handling data within the database,
including most SQL statements.

12 | P a g e
REPLACE:
this keyword if the entity is already is present then it modify it if it is not present then it insert it.

SQL REPLACE()
The REPLACE() function is a string function in SQL to replace all occurrences of a specified string with

another string in the result set.


It is important to note that REPLACE() does not modify the data in the actual database table, it only alters

the data in the query result.


Example

SELECT REPLACE(first_name, 'John', 'Jonathan') AS updated_names


FROM Customers;

Here, the result set of this query replaces all occurrences of John with Jonathan in
the first_name column of the Customers table.

Difference between update and replace:


If data is not present then replace insert the data where as if the is not present then update do nothing;

JOINs:

13 | P a g e
14 | P a g e
15 | P a g e
16 | P a g e
17 | P a g e
18 | P a g e
19 | P a g e
20 | P a g e
Union :

Intersection :

MINUS :

21 | P a g e
22 | P a g e
23 | P a g e
24 | P a g e
25 | P a g e

You might also like