Best Jquery ,javascript, HTML5 CSS3 tutorial with jquery examples, php script , demos for beginners, web designers and web developers.

Jquery

Jquery Training

Jquery training blog

What is right join

Right JOIN MySQL or Sql JOINS are used to retrieve data combining two or more tables based on the relation between the columns of the tables. MySQL JOIN or Sql JOIN is executed by a SQl statement. When we require to retrieve data from two or more tables base on some relation, SQL or MySQl Continue Reading


Right JOIN

MySQL or Sql JOINS are used to retrieve data combining two or more tables based on the relation between the columns of the tables. MySQL JOIN or Sql JOIN is executed by a SQl statement.

When we require to retrieve data from two or more tables base on some relation, SQL or MySQl join is performed. Joining of tables involves the tricks to retrieve data from multiple table using a SQL statement.

 

We will discuss about right join
in this post:

RIGHT JOIN : RIGHT JOIN returns all the table rows from second table and matching rows from the first table.

See the below image ,

 

Sql right join

Lets explain with the example
Create two table admission and student

Admission table SQL

CREATE TABLE `admission` (
  `id` int(11) NOT NULL,
  `stdID` int(11) NOT NULL,
  `admission_date` varchar(25) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `admission` (`id`, `stdID`, `admission_date`) VALUES
(1, 1, '14-12-2016'),
(2, 3, '11-12-2016');

The admission table look like below

id stdID admission_date
1 1 14-12-2016
1 3 11-12-2016

Student table SQL

CREATE TABLE `student` (
  `id` int(11) NOT NULL,
  `sname` varchar(100) NOT NULL,
  `fname` varchar(100) NOT NULL,
  `address` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


INSERT INTO `student` (`id`, `sname`, `fname`, `address`) VALUES
(1, 'Joy', 'Dev', 'Siliguri'),
(2, 'Rahul\r\n', 'Samrat', 'Chanmasari'),
(3, 'Rakesh', 'Dam', 'Jalpaiguri'),
(4, 'Chandan', 'Sridhar', 'Darjeeling\r\n');

The Student table look like below

id sname fname address
1 Joy Dev Siliguri
2 Rahul Samrat Champasari
3 Rakesh Dam Jalpaiguri
4 Chandan Sridhar Darjeeling

Now we want to select all the student who has taken admision.
Write the following query to fetch all the student who has taken admission

SELECT student.id, student.sname, student.fname, admission.admission_date
FROM student
Right JOIN admission ON admission.stdID=student.id

The out put of Right join

id sname fname admission_date
1 Joy Dev 14-12-2016
2 Rakesh Dam 11-12-2016

In the above example, the query returns all the rows from second table and matching row from the first table

Please follow and like us:






About the author

Joydeb Choudhury holds a Master's degree in Computer Application from I.G.N.O.U. After working as a web developer in various companies he has started bloging in 2016.

Recent Posts of blog

Downalod Free Php Scripts