0% found this document useful (0 votes)
6 views24 pages

SQL Notes

The document provides an overview of databases, including definitions of database, DBMS, and RDBMS, along with their characteristics and examples. It explains the necessity of databases for managing large data sets and outlines the advantages of using them. Additionally, it covers SQL commands and constraints, detailing how to manipulate and query data effectively within a database.

Uploaded by

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

SQL Notes

The document provides an overview of databases, including definitions of database, DBMS, and RDBMS, along with their characteristics and examples. It explains the necessity of databases for managing large data sets and outlines the advantages of using them. Additionally, it covers SQL commands and constraints, detailing how to manipulate and query data effectively within a database.

Uploaded by

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

I-RISE SOFTWARE TRAINING INSTITUTE

❖ What is Database?
• A database is used to store the collection of records in an organized form. It allows us to hold the
data into tables, rows, columns, and indexes to find the relevant information frequently.
• We can access and manage the records through the database very easily.
OR
• A database is a well-organized collection of data that is stored in an electronic format
• It is an electronic system which allows user to easily access, manipulate and update the data.

DBMS (Database Management System):


• It is a system which keeps or stores the data in the format of file and allows to perform different
operations on it.
• In DBMS, data is generally stored in either a hierarchical form or a navigational form.
• DBMS is meant to be for small organization and deal with small data. it supports single user.
• Examples of DBMS are file systems, excel etc.

RDBMS (Relational Database Management Systems).


• MySQL is a relational database management system. This database language is based on the SQL
queries to access and manage the records of the table.
• It is a system which keeps or stores the data in the format of table and allows to perform different
operations on it.
• In RDBMS, the tables have an identifier called primary key and the data values are stored in the
form of tables.
• RDBMS is designed to handle large amount of data. it supports multiple users.
• Example of RDBMS are mysql, Postgres, SQL server, oracle etc.
I-RISE SOFTWARE TRAINING INSTITUTE

❖ Why we need Database?


• Manage large amounts of data
• Difficult to manage data in spreadsheets.
• Manual validation of data in spreadsheet is difficult
• Flexibility to update data in Database.
• Multiple people can edit Data at same time.

❖ ADVANTAGES:
1. Easy to use
2. It is secure
3. Client/ Server Architecture
4. Free to download
5. It is scalable/ expandable.
6. Speed
7. High Performance
I-RISE SOFTWARE TRAINING INSTITUTE

❖ What SQL can do?


• SQL can retrieve data from a database
• SQL can insert records in a database
• SQL can update records in a database
• SQL can delete records from a database
• SQL can create new databases
• SQL can create new tables in a database
• SQL can create views in a database
• SQL can set permissions on tables, procedures, and views

❖ SQL- Structured Query Language:


• SQL is a standard language for storing, manipulating and retrieving data in databases
• SQL keywords are NOT case sensitive Ex. SELECT as select .
• Semicolon is the standard way to separate each SQL statement in database systems.
Ex. Select * from employee (Table name);
• Standard language for dealing with Relational Database which can be used to Create, Read,
Update and Delete database records (CRUD Operations).

❖ SQL Commands:
Divided into four categories:
• Data Query Language (DQL Commands in SQL)
• Data Definition Language (DDL Commands in SQL)
• Data Manipulation Language (DML Commands in SQL)
• Data Control Language (DCL Commands in SQL)

❖ Data Query Language (DQL Commands in SQL)


• DQL is used to fetch the data from the database.
• Data Query Language comprises only one command ‘SELECT’. This command can be
accompanied by many other clauses to compose queries.
• SELECT It retrieves the data/information from the database/table.
I-RISE SOFTWARE TRAINING INSTITUTE

❖ Data Definition Language (DDL Commands in SQL)


• The basic DDL commands in SQL are Create Tables, Alter Tables, Drop Tables and Truncate
Tables.
• DDL is used to perform the Create Tables/database, Alter Tables/Database, Drop Table/database
and Truncate Table/database.
• All DDL commands are auto-committed that means it permanently save all the changes in the
database.

❖ Data Manipulation Language (DML Commands in SQL)


• To deal with the data itself directly.
• SQL Commands is used to perform the operations: INSERT, UPDATE, and DELETE.
• DML commands are used to modify the database
Command What it does?
INSERT Add new information to the table
UPDATE Modifies the information currently Stored in
the table
DELETE Delete information from the table
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
***QUERY’S***
Database
Query: show databases;
Create Database Query: create database database_name;
To use database Query: Use database_name;
Delete Database; Query: Drop database database_name;
Show table;
I-RISE SOFTWARE TRAINING INSTITUTE

❖ Data Query Language (DQL):

➢ Select: -
• It is an SQL command which is used to fetch or retrieved the data from database.
SYNTAX: -
Select * from Table_Name;
• SELECT Column_Name_1, Column_Name_2, Column_ Name_ 3 FROM Table _Name;
Example: - Select * from signup;

❖ Data Definition Language (DDL):


1 Create: - SQL CREATE TABLE statement is used to create table in a database.
SYNTAX: -
CREATE TABLE table_name (
Column name datatype,
Column name datatype,
Column name datatype
);

▪ Example: -
Create table student (
Id int,
First_Name varchar (50).
Last_Name(50)
);
2) Alter:-
The ALTER statement is always used with "ADD", "DROP" and "MODIFY" commands according
to the situation.
1 ADD: To add a column in the table
Syntax: : alter table Table_name ADD Column name datatype;
Example :- alter table Students Details add Class varchar(50);
I-RISE SOFTWARE TRAINING INSTITUTE

2 DROP: To drop column in the table


Syntax: alter table Table name DROP Column name;
Example : alter table irise DROP EMAIL;
3 MODIFY: To modify column in the table
Syntax: alter table Table name MODIFY Column name datatype;
Example : alter table Students_Details modify S_mobile varchar(12);
4 CHANGE : To change the column name
You must specify the new name and new definition(datatype)
Syntax : alter table table_name CHANGE COLUMN old_column_name new_column_name
datatype;
Example : alter table student CHANGE COLUMN name student_name varchar(50);
5 RENAME : (MySQL 8.0+)
To RENAME the column
Used to rename a column only (no need to change data type)
Syntax : alter table table_name RENAME COLUMN old_column_name TO new_column_name;
Example : alter table student RENAME COLUMN name TO student_name;

❖ Data Manipulation Language (DML Commands in SQL)


1)Insert Into:-
It is an SQL statement which is used to add the record/data into the particular table.
Syntax :-
INSERT INTO table name(coloumn1, coloumn2, coloumn3, coloumn4) values (value1, value2,
value3, value4);
Example :-
INSERT INTO irise (ID, Name, Surname, SALARY) values (1, “abc”, “xyz”, 920000);
For multiple value insertion without taking field(column name)
INSERT INTO table_name VALUES(value1, value2, value3), (value1, value2, value3);
I-RISE SOFTWARE TRAINING INSTITUTE

2)Update:-
It is an SQL statement which is used to update the existing record into the table.
Syntax:- Update table_name SET column name= “Updated value” Where column name= existing
column value;
Example : UPDATE demo SET surname = “lmn” where id=1; (NOTE):
TO REMOVE THE ERROR for UPDATE QUERY USE FOLLOWING SYNTAX EXECUTE
FIRST-> SET SQL_SAFE_UPDATES = 0; (TO disABLE SAFE MODE)
Execute SECOND-> update MAD_STUDENTS9 set salary = 10000 where ID=3;
SET SQL_SAFE_UPDATES = 1; (NO NEED TO WRITE THESE QUERY)
3)Delete:-
It is an SQL statement which is used to delete the existing record from the table.
Syntax:- Delete from table name Where column name = column value (which defined as primary
key);
Example: delete from demo Where id= 1;

❖ CONSTRAINT

Constraint:- The constraint in SQL is used to specify the rule that allows or restricts what
value/data will be stored in table.
It also helps to limit the type of data that will be inserted inside the table.
1)NOTNULL
2)UNIQUE
3)Check
4)Default
5) Primary key
6) Foreign key
I-RISE SOFTWARE TRAINING INSTITUTE

NotNull :- This constraint specifies that column cannot have null.


(i.e. Mandatory field)
Example:
CREATE TABLE demo8 (
id INT NOT NULL,
name VARCHAR(45) NOT NULL,
surname VARCHAR(45) ,
gmail VARCHAR(45)
);

1) NOT NULL :-
The NOT NULL constraint ensures that a column cannot have a NULL value.
It is used when a column must always contain a value, i.e., it's a mandatory field.
Empty string is allowed in NOT NULL column.
Example:-

➢ CREATE TABLE student (


st_id INT NOT NULL,
name VARCHAR(45) NOT NULL,
surname VARCHAR(45),
gmail VARCHAR(45)
);

➢ INSERT INTO student (st_id, name, surname, gmail)


VALUES (10, “Kishor”, “Rathod”, “kishor@gmail.com”);

➢ INSERT INTO student (id, name, surname, gmail)


VALUES (11, NULL, 'yzx', 'abcpatil@gmail.com');
-- This will throw an error due to NOT NULL constraint on 'name'
I-RISE SOFTWARE TRAINING INSTITUTE

2) UNIQUE :-
The UNIQUE constraint ensures that all values in a column are distinct.
This means no duplicate values can be stored in the specified column.
You can apply the UNIQUE constraint to one or more columns in a table.
Example :-

➢ CREATE TABLE demo9 (


id INT NOT NULL,
name VARCHAR(45) UNIQUE,
surname VARCHAR(45),
gmail VARCHAR(45)
);

➢ INSERT INTO student(id, name, surname, gmail)


VALUES (11, 'Deva', 'patil', 'patil@gmail.com');

➢ INSERT INTO student (id, name, surname, gmail)


VALUES (12, 'Deva', 'patil', 'patil@gmail.com');
-- This will throw an error because 'Rajveer' already exists in the 'name' column
3) CHECK :-
The CHECK constraint is used to limit the value range that can be placed in a column..
It ensures data validity by allowing only the values that satisfy a specific condition.
Example :-

➢ CREATE TABLE demo15 (


id INT PRIMARY KEY,
name VARCHAR(45),
surname VARCHAR(45),
email VARCHAR(45),
age INT CHECK (age >= 18)
);
I-RISE SOFTWARE TRAINING INSTITUTE

➢ INSERT INTO demo15(id, name, surname, email, age)


VALUES (1, 'abc', 'xyz', 'abc@gmail.com', 19);

➢ INSERT INTO demo15(id, name, surname, email, age)


VALUES (2, 'lmn', 'xyz', 'lmn@gmail.com', 16);
-- This will throw an error due to CHECK constraint on age

4) Default:-
This constraint is used to set a default value for the particular column where we have not
specified any value.
Example:-
CREATE TABLE student5 (
st_id int NOT NULL,
name varchar(255) NOT NULL,
sirname varchar(255),
address varchar(255) DEFAULT ‘Pune’
);
INSERT INTO student5 (st_id, name, surname, address) VALUES
(1, 'Ravi', 'Patil', DEFAULT), -- uses default: 'pune'
(2, 'Sita', 'Joshi', 'Mumbai'), -- explicit value
(3, 'Amit', 'Kumar', DEFAULT), -- uses default: 'pune'
(4, 'Reena', 'Shah', 'Delhi');
❖ With single query
insert into student5(st_id,name,surname) values (11,"kishor","Rathod");
I-RISE SOFTWARE TRAINING INSTITUTE

5) Primary key:-
The primary key constraint is used to identify each record in a table. The column contains the
primary key constraint it cannot be null OR empty. In a table there is only one primary key.
Based on the primary key you can join the two tables or more tables. The primary key
constraints column must have unique value.

• MySQL treats ' ' as a valid string value — it's not NULL.
• MySQL allows one empty string ('') as a valid PRIMARY KEY only if the column is
of type VARCHAR or CHAR.
• Primary key allows only one unique empty string, just like it would allow one unique
name like 'Ravi'.
• But if the column is of type INT or BIGINT, then trying to insert ' ' is often
automatically cast to 0, which might raise a different kind of error.

Example :-
CREATE TABLE student (
id INT primary key,
name VARCHAR(45) ,
surname VARCHAR(45) ,
Gmail VARCHAR(45)
);

INSERT INTO student(`id`,`name`,`surname`,`Gmail`)


VALUES (13,'vishal','jadhav','vishal@gmail.com');

6) Foreign key :-
This constraint is used to link two tables together. It is also known as the referencing key. A
foreign key column matches the primary key field of another table. It means that the foreign
key field in one table refer to the primary key field of another table.
I-RISE SOFTWARE TRAINING INSTITUTE

Example :-
Creating table:-
• Creating Table -> Cities
CREATE TABLE Cities (
ID INT PRIMARY KEY,
City varchar(50) NOT NULL
);
• Creating Table -> Student_Details
CREATE TABLE Student_Details(
Name varchar(50) NOT NULL,
Email varchar(50) NOT NULL,
S_Id INT,
FOREIGN KEY (S_Id) REFERENCES Cities(ID)
);

• Inserting values in Table -> cities


insert into cities(id, city) values(1, "Pune"), (2, "Mumbai"), (3, "Nagpur"),
(4, "Sambhaji Nagar"), (5, "Latur");
• Inserting values in Table -> Student
insert into Student_Details(Name, Email, s_id)
values("Amit", "amit@gmail.com", 1),
("Shubham", "shubham@gmail.com", 2),
("Puja", "puja@gmail.com", 1),
("Yash", "yash@gmail.com", 2);
I-RISE SOFTWARE TRAINING INSTITUTE

****Clauses****
• It is use to apply filters on the queries and get the filtered queries in result set.
1) Where
2) Order By
3) Distinct
4) Group By
5) Having

❖ Where clause:-

• It is an sql command which is used to extract only those record which full fill the
specified condition. The WHERE clause is used to filter records
• If you only want to see data for a certain department, salary range, or city, WHERE
helps filter out the rest.
Syntax: select * from table name where Column name = value;
Example : select * from employee where st_id=11;

❖ Order By clause:-

• It is an sql command which is used to sort the result set in ascending and descending
order.
• Used when you want results in a specific order like salary high to low, names
alphabetically, etc.

❖ Descending order:
Syntax: select * from Table name order by Column name desc;
Example : select * from employee order by Surname desc ;

❖ Ascending order:
Syntax: select * from Table name order by Column name asc;
Example : select * from employee order by Surname asc ;
I-RISE SOFTWARE TRAINING INSTITUTE

❖ Distinct:-

• Used to remove duplicate values from the result set. It ensures each returned row is
unique.
• If a column has repeating values (like department names), but you want to list each
unique one only.
Syntax :- SELECT DISTINCT column1 FROM table_name;
Example :- SELECT DISTINCT department FROM employees;

***Aggregate Functions ***


Aggregate functions perform a calculation on a set of values and return a single value,
They operate on multiple rows but return a single summary value.
It is used when we want summary information such as totals, averages, counts,
minimum/maximum values — commonly used with GROUP BY.
1) COUNT (): -
Returns the number of rows (or non-null values in a column).
Example ::- counting how many employee are present in a office.
Syntax:- SELECT COUNT (column_name) FROM table_name;
Example: - SELECT COUNT (*) FROM employees;
2) SUM (): -

Returns the total sum of a numeric column (e.g., salaries, expenses).


Like adding up everyone's monthly salary to find the company’s total payroll.

Syntax:- SELECT SUM(column_name) FROM table_name;


Example:- SELECT SUM(salary) AS total_salary FROM employees;

3) AVG (): -

Returns the average value of a numeric column.


calculating the average salary of all employee.

Syntax:- SELECT AVG(column_name) FROM table_name;


Example:- SELECT AVG(salary) AS avg_salary FROM employees;
I-RISE SOFTWARE TRAINING INSTITUTE

4) MIN (): -
Returns the smallest (minimum) value in a column.
Finding the employee with lowest salary in the company.
Sysntax: - SELECT MIN(column_name) FROM table_name;
Example:- SELECT MIN(salary) AS min_salary FROM employees;
5) MAX(): -
Returns the largest (maximum) value in a column.
Finding the highest salary from employees.

Syntax:- SELECT MAX(column_name) FROM table_name;


Example:- SELECT MAX(salary) AS max_salary FROM employees;

3) Group By Clause:-
GROUP BY helps us group similar rows together and then apply calculations like total, average, or
count on each group.
Syntax: select Column name , Aggregate function from Table name group by column name
Example:
BY USING ONLY GROUP BY CLAUSE and USING AGGREGATE FUNCTION COUNT
1. select CITY, count(CITY) from employees group by CITY;
BY USING WHERE CLAUSE WITH GROUP BY CLAUSE
2. select CITY, count(CITY) from employees where Age>=27 group by CITY;
BY USING ONLY GROUP BY CLAUSE and USING AGGREGATE FUNCTION SUM
3.select AGE, sum(AGE) as "SUM OF AGE" from employees group by AGE;
BY USING ONLY GROUP BY CLAUSE and USING AGGREGATE FUNCTION MIN
4.select CITY, min(AGE) as "minimum age" from employees group by CITY;
BY USING ONLY GROUP BY CLAUSE and USING AGGREGATE FUNCTION MAX
5.select CITY, max(AGE) as "maximum age" from employees group by CITY;
BY USING ONLY GROUP BY CLAUSE and USING AGGREGATE FUNCTION AVG
6.select CITY, avg(AGE) as "average age" from employees group by CITY;
I-RISE SOFTWARE TRAINING INSTITUTE

We can use GROUP BY with multiple columns.


SELECT CITY, AGE, COUNT(CITY) FROM employees GROUP BY CITY, AGE;

❖ Having clause:-

• It is used to filter the record. As we know that we cannot use the where clause with
aggregate function that’s the reason we are using having clause
• HAVING Clause is used with the GROUP BY clause. It always returns the rows where the
condition is TRUE.
Syntax: Select Column name, aggregate function(column name)as “New column name” from
table name group by column name having aggregate function (column name) condition
Example:1: select CITY, avg(AGE) as "average age" from employees group by CITY having
avg(AGE)<32;
Example :2: select CITY, sum(salary) as "sum of salary" from employees group by CITY
having sum(salary)>55000;
Two aggregate functions on two column
Example:3: SELECT city, SUM(salary) AS total_salary, AVG(age) AS average_age
FROM employees GROUP BY city HAVING SUM(salary) > 5000 AND
AVG(age) < 30;

❖ Alias in SQL (AS Keyword):-


An Alias in SQL is a temporary name given to a column or table in a query. It is mainly used to
make the output more readable or to simplify long or complex column names.

• Improves readability of query results.


• Simplifies column or table names.
• Useful while working with joins or subqueries to avoid confusion.

Syntax:-
For Column Alias:
SELECT column_name AS alias_name FROM table_name;
I-RISE SOFTWARE TRAINING INSTITUTE

Example:-
SELECT AGE AS selfage FROM employees;

For Table Alias:


SELECT column1, column2 FROM table_name AS alias_name;
Example:- SELECT * FROM employees AS employs;

Note: -
Aliases are temporary—they only exist during the execution of the SQL query.
The AS keyword is optional but recommended for clarity.
Avoid using reserved SQL keywords as alias names.

❖ AND Condition in SQL: -


The AND condition is used to combine multiple conditions in a SQL query. The result will include
only those rows where all conditions are true.
Syntax: SELECT * FROM table_name WHERE condition1 AND condition2;
Example: - SELECT * FROM employees WHERE Age <= 34 AND City = “Pune”;

❖ OR Condition in SQL: -
The OR condition in SQL returns rows when any one of the conditions is true. It is more flexible
than AND.
Syntax: SELECT * FROM table_name WHERE condition1 OR condition2;
Example: - SELECT * FROM employees WHERE Age <= 29 OR City = “Pune”;
I-RISE SOFTWARE TRAINING INSTITUTE

❖ UNION& UNION ALL :-


In SQL, both UNION and UNION ALL are used to combine the results of two or more SELECT
queries. However, they have some key differences in how they handle the rows in the result set.

❖ UNION: -
• The UNION operator combines the result sets of two or more SELECT statements into a
single result set.
• Eliminates Duplicate Rows: When you use UNION, the result will only contain unique
rows. Any duplicate rows are automatically removed.
Rules for Using UNION:
• Each SELECT statement involved in the UNION must have the same number of columns.
• The data type of the columns must be the same in each SELECT statement.
• The columns in each SELECT statement must appear in the same order.

CREATE TABLE student1 (


stud_id INT,
stud_name VARCHAR(56),
subject VARCHAR(34),
marks INT
);

INSERT INTO student1 VALUES


(1, 'Mark', 'English', 68),
(2, 'Joseph', 'Physics', 70),
(3, 'John', 'Maths', 70),
(4, 'Barack', 'Maths', 90),
(5, 'Rinky', 'Maths', 85),
(6, 'Adam', 'Science', 92);

SELECT * FROM student1;


CREATE TABLE student2 (
stud_id INT,
stud_name VARCHAR(56),
subject VARCHAR(34),
marks INT
);

INSERT INTO student2 VALUES


(1, 'Donald', 'History', 85),
(2, 'Joseph', 'Physics', 70),
(3, 'Stephen', 'Geography', 82),
(4, 'Abraham', 'Java', 75);

SELECT * FROM student2;

Syntax: - SELECT stud_name, subject FROM student1


UNION
SELECT stud_name, subject FROM student2;

❖ UNION ALL :-
The UNION ALL operator combines the result sets of two or more SELECT queries, just like
UNION, but does not remove duplicates.
Retains Duplicate Rows: If a row appears in multiple SELECT statements, it will appear multiple
times in the result set.
Use UNION ALL when you want to keep all rows from the combined result set, including
duplicates.
It's generally faster than UNION because it does not require the additional processing of removing
duplicates.
I-RISE SOFTWARE TRAINING INSTITUTE

SELECT stud_name, subject FROM student1


UNION ALL
SELECT stud_name, subject FROM student2;

❖ LIKE:-
1. In MySQL, LIKE condition is used to perform pattern matching to find the correct result.
2. It is used in SELECT, INSERT, UPDATE and DELETE statement with the combination of
WHERE clause.
3. There are two wildcards often used in conjunction with the LIKE operator:
• The percent sign (%) represents zero, one, or multiple characters

• The underscore sign (_) represents one, single character ✓


WILDCARD(‘%’)

Example 1: select * from emp where Surname like 'p%' ; (characters start from pa)
Example 2: select * from emp where Surname like '%ri ' ; (characters ends from ri)
Example 3: select * from emp where Surname like '%au%' ; (characters between au)
Example 4: select * from emp where Surname like '%a%' ; (middle character a)
Example 4: select * from emp where surname like 's%a';
(Surnames starting with "S" and ending with "a")
Example 5: select * from emp where surname like '%an%'; (Surnames that contain "an")
I-RISE SOFTWARE TRAINING INSTITUTE

Example 1: SELECT * FROM emp WHERE Surname LIKE 'pa_____';


(Surnames with exactly 7 letters starting with "pa")
Example 2: SELECT * FROM emp WHERE Surname LIKE '____';
(Surnames with exactly 4 letters)
Example 3: SELECT * FROM emp WHERE Surname LIKE '_a%';
(Surnames with second character 'a')
Example 4: SELECT * FROM emp WHERE Surname LIKE '____' OR Surname LIKE ‘pa_____’;
I-RISE SOFTWARE TRAINING INSTITUTE

***JOINS***
It is used to combine rows from one or more tables based on related column in between them.
1. Inner Join
2. Left Join / Left Outer Join
3. Right Join/ Right Outer join
4. Full Join

INNER JOIN:-
It is returning only those records which is having matching values in both table and hides
other rows and columns.

Syntax:- SELECT Table1.Column_name,Table1.Column_name,Table2.Column_name


FROM Table1
INNER JOIN Table2
ON Table1.comman_column = Table2.comman_column
Example:-
SELECT Employee.EmpID, Employee.EmpName, Department.DeptName
FROM Employee
INNER JOIN Department
ON Employee.DeptID = Department.DeptID;
I-RISE SOFTWARE TRAINING INSTITUTE
LEFT JOIN:-
Left join returns all record from the left table and matching records from right. The result
shows null if there is no matching from right side.

Syntax:- SELECT Table1.Column_name,Table1.Column_name,Table2.Column_name


FROM Table1
LEFT JOIN Table2
ON Table1.comman_column = Table2.comman_column
Example:-
SELECT Employee.EmpID, Employee.EmpName, Department.DeptName
FROM Employee
LEFT JOIN Department
ON Employee.DeptID = Department.DeptID;

RIGHT JOIN:-
The right join returns all the record from right table and matching record from left table.
The result shows null from the left side where there is no match.
I-RISE SOFTWARE TRAINING INSTITUTE

Syntax:- SELECT Table1.Column_name,Table1.Column_name,Table2.Column_name


FROM Table1
RIGHT JOIN Table2
ON Table1.comman_column = Table2.comman_column
Example:-
SELECT Employee.EmpID, Employee.EmpName, Department.DeptName
FROM Employee
RIGHT JOIN Department
ON Employee.DeptID = Department.DeptID;

FULL JOIN:-
A FULL JOIN returns all rows when there is a match in either the left or right table. It will
include records with matching values from both tables and those with no match in either table.
Note: If you're using MySQL (which doesn’t support FULL JOIN)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy