• About
  • Privacy & Policy
  • Contact
TETRALEARN
  • Home
  • News
    • All
    • IT Events
    • Science
    • Technology
    Maximizing Performance Testing Efficiency with JMeter

    Maximizing Performance Testing Efficiency with JMeter

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Understanding PostgreSQL

    Understanding PostgreSQL

    Best Tools for Software Testing

    Best Tools for Software Testing

    Blockchain Technology

    Blockchain Technology

    Selenium Automation Testing

    Selenium Automation Testing

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Projects
    • All
    • Apps
    • Mobile Apps
    • Web Applications
    Maximizing Performance Testing Efficiency with JMeter

    Maximizing Performance Testing Efficiency with JMeter

    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Understanding SRS

    Understanding SRS

    Understanding FRS

    Understanding FRS

    Best Tools for Software Testing

    Best Tools for Software Testing

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Programming
    • All
    • Laravel
    • PHP
    • Python
    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Highlights and Challenges of JavaScript

    Highlights and Challenges of JavaScript

    Angular Framework Features

    Angular Framework Features

    LARAVEL FEATURES

    LARAVEL FEATURES

    OOPS in PHP

    OOPS in PHP

    JavaScript Object Notation(JSON)

    JavaScript Object Notation(JSON)

  • Tutorials
    • All
    • Database Tutorial
    • Digital Marketing
    • Programming
    Application Programming Interface

    Application Programming Interface

    Twitter Tools and Tutorials For Designers and Developers

    Twitter Tools and Tutorials For Designers and Developers

    WORDPRESS FUNDAMENTAL

    WORDPRESS FUNDAMENTAL

    Understand JOINS in RDBMS

    Understand JOINS in RDBMS

    Best SEO Tips

    Best SEO Tips

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Vacancies
No Result
View All Result
  • Home
  • News
    • All
    • IT Events
    • Science
    • Technology
    Maximizing Performance Testing Efficiency with JMeter

    Maximizing Performance Testing Efficiency with JMeter

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Understanding PostgreSQL

    Understanding PostgreSQL

    Best Tools for Software Testing

    Best Tools for Software Testing

    Blockchain Technology

    Blockchain Technology

    Selenium Automation Testing

    Selenium Automation Testing

    Trending Tags

    • Trump Inauguration
    • United Stated
    • White House
    • Market Stories
    • Election Results
  • Projects
    • All
    • Apps
    • Mobile Apps
    • Web Applications
    Maximizing Performance Testing Efficiency with JMeter

    Maximizing Performance Testing Efficiency with JMeter

    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Yii Framework: Turbocharge Your Web Development Projects Like Never Before

    Understanding SRS

    Understanding SRS

    Understanding FRS

    Understanding FRS

    Best Tools for Software Testing

    Best Tools for Software Testing

    Trending Tags

    • Nintendo Switch
    • CES 2017
    • Playstation 4 Pro
    • Mark Zuckerberg
  • Programming
    • All
    • Laravel
    • PHP
    • Python
    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

    Highlights and Challenges of JavaScript

    Highlights and Challenges of JavaScript

    Angular Framework Features

    Angular Framework Features

    LARAVEL FEATURES

    LARAVEL FEATURES

    OOPS in PHP

    OOPS in PHP

    JavaScript Object Notation(JSON)

    JavaScript Object Notation(JSON)

  • Tutorials
    • All
    • Database Tutorial
    • Digital Marketing
    • Programming
    Application Programming Interface

    Application Programming Interface

    Twitter Tools and Tutorials For Designers and Developers

    Twitter Tools and Tutorials For Designers and Developers

    WORDPRESS FUNDAMENTAL

    WORDPRESS FUNDAMENTAL

    Understand JOINS in RDBMS

    Understand JOINS in RDBMS

    Best SEO Tips

    Best SEO Tips

    Trending Tags

    • Golden Globes
    • Game of Thrones
    • MotoGP 2017
    • eSports
    • Fashion Week
  • Vacancies
No Result
View All Result
TETRALEARN
No Result
View All Result
Home Tutorials Database Tutorial

Understand JOINS in RDBMS

Tetra Learn by Tetra Learn
July 7, 2022
in Database Tutorial, Uncategorized
39
Understand JOINS in RDBMS
0
SHARES
113
VIEWS
Share on FacebookShare on Twitter

Also check:- Best SEO Tips

“JOIN” is a SQL keyword used to query data from two or more related tables. Unfortunately, the concept is regularly explained using abstract terms or differs between database systems. It often confuses me. Developers cope with enough confusion, so this is my attempt to explain JOINs briefly and succinctly to myself and anyone who’s interested.

Related Tables

MySQL, PostgreSQL, Firebird, SQLite, SQL Server and Oracle are relational database systems. A well-designed database will provide a number of tables containing related data. A very simple example would be users (students) and course enrollments:

‘user’ table:

Idnamecourse
1Alice1
2Bob1
3Caroline2
4David5
5Emma(NULL)

MySQL table creation code:

CREATE TABLE `user` (
	`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
	`name` varchar(30) NOT NULL,
	`course` smallint(5) unsigned DEFAULT NULL,
	PRIMARY KEY (`id`)
) ENGINE=InnoDB;

The course number relates to a subject being taken in a course table…

‘course’ table:

idName
1HTML5
2CSS3
3JavaScript
4PHP
5MySQL

MySQL table creation code:

CREATE TABLE `course` (
	`id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
	`name` varchar(50) NOT NULL,
	PRIMARY KEY (`id`)
) ENGINE=InnoDB;

Since we’re using InnoDB tables and know that user.course and course.id are related, we can specify a foreign key relationship:

ALTER TABLE `user`
ADD CONSTRAINT `FK_course`
FOREIGN KEY (`course`) REFERENCES `course` (`id`)
ON UPDATE CASCADE;

In essence, MySQL will automatically:

  • re-number the associated entries in the user.course column if the course.id changes
  • reject any attempt to delete a course where users are enrolled.

important: This is terrible database design!

This database is not efficient. It’s fine for this example, but a student can only be enrolled on zero or one course. A real system would need to overcome this restriction — probably using an intermediate ‘enrollment’ table which mapped any number of students to any number of courses.

JOINs allow us to query this data in a number of ways.

INNER JOIN (or just JOIN)

SQL INNER JOIN
The most frequently used clause is INNER JOIN. This produces a set of records which match in both the user and course tables, i.e. all users who are enrolled on a course:
SELECT user.name, course.name
FROM `user`
INNER JOIN `course` on user.course = course.id;
user.namecourse.name
AliceHTML5
BobHTML5
CarlineCSS3
DavidMySQL

LEFT JOIN

SQL LEFT JOIN
What if we require a list of all students and their courses even if they’re not enrolled on one? A LEFT JOIN produces a set of records which matches every entry in the left table (user) regardless of any matching entry in the right table (course):
SELECT user.name, course.name
FROM `user`
LEFT JOIN `course` on user.course = course.id;

Result:

user.namecourse.name
AliceHTML5
BobHTML5
CarlineCSS3
DavidMySQL
Emma(NULL)

RIGHT JOIN

SQL RIGHT JOIN
Perhaps we require a list all courses and students even if no one has been enrolled? A RIGHT JOIN produces a set of records which matches every entry in the right table (course) regardless of any matching entry in the left table (user):
SELECT user.name, course.name
FROM `user`
RIGHT JOIN `course` on user.course = course.id;

Result:

user.namecourse.name
AliceHTML5
BobHTML5
CarlineCSS3
(NULL)JavaScript
(NULL)PHP
DavidMySQL
RIGHT JOINs are rarely used since you can express the same result using a LEFT JOIN. This can be more efficient and quicker for the database to parse:
SELECT user.name, course.name
FROM `course`
LEFT JOIN `user` on user.course = course.id;

We could, for example, count the number of students enrolled on each course:

SELECT course.name, COUNT(user.name)
FROM `course`
LEFT JOIN `user` ON user.course = course.id
GROUP BY course.id;

Result:

course.namecount()
HTML52
CSS31
JavaScript0
PHP0
MySQL1

OUTER JOIN (or FULL OUTER JOIN)

SQL FULL OUTER JOIN
Our last option is the OUTER JOIN which returns all records in both tables regardless of any match. Where no match exists, the missing side will contain NULL.

OUTER JOIN is less useful than INNER, LEFT or RIGHT and it’s not implemented in MySQL. However, you can work around this restriction using the UNION of a LEFT and RIGHT JOIN, e.g.

SELECT user.name, course.name
FROM `user`
LEFT JOIN `course` on user.course = course.id
UNION
SELECT user.name, course.name
FROM `user`
RIGHT JOIN `course` on user.course = course.id;

Result:

user.namecourse.name
AliceHTML5
BobHTML5
CarlineCSS3
DavidMySQL
Emma(NULL)
(NULL)JavaScript
(NULL)PHP
I hope that gives you a better understanding of JOINs and helps you write more efficient SQL queries.

Tags: JOINs in RDBMSMYSQLPostgreSQLRDBMSSQLUnderstand JOINS in RDBMS
Previous Post

Best SEO Tips

Next Post

WORDPRESS FUNDAMENTAL

Tetra Learn

Tetra Learn

Next Post
WORDPRESS FUNDAMENTAL

WORDPRESS FUNDAMENTAL

Comments 39

  1. Pingback: WORDPRESS FUNDAMENTAL - TETRALEARN
  2. VINAY Yadav says:
    3 years ago

    Thank you for giving me knowledge this blog is very useful for me, again thank you.

    Reply
  3. Swagatika says:
    3 years ago

    Useful for me thanx 👍

    Reply
  4. Atul singh says:
    3 years ago

    Love this blog, very informative thank you

    Reply
  5. Aryan ray says:
    3 years ago

    Very informative blog. Helped me a lot.

    Reply
  6. Soumya says:
    3 years ago

    Thank you for such infomative blog

    Reply
  7. Bhagyashree Pradhan says:
    3 years ago

    Very good blog.

    Reply
  8. sasmitanjali nayak says:
    3 years ago

    i am soo happy find your channel..nice blog

    Reply
  9. Subham jyoti pradhan says:
    3 years ago

    Very informative blog . Helped me a lot .

    Reply
  10. Sara faiza says:
    3 years ago

    Very nice content. Very useful blog

    Reply
  11. Naren ray says:
    3 years ago

    Very informative blog. Helped me a lot.

    Reply
  12. Rohit Nandurkar says:
    3 years ago

    Very good content

    Reply
  13. Ayesha Siddiqua says:
    3 years ago

    Very good blog

    Reply
  14. Vicky Kumar says:
    3 years ago

    Nice. Very informative.

    Reply
  15. Nilay says:
    3 years ago

    Thank you for such a informative blog.

    Reply
  16. Prince Gopal says:
    3 years ago

    such a informative blog.👍

    Reply
  17. Balram Patel says:
    3 years ago

    Very Nice ….And good Knowledge for me
    Thanks For sharing 😊

    Reply
  18. Huzaif Banday says:
    3 years ago

    Nice 👌 informative

    Reply
  19. Deepanshi Singh says:
    3 years ago

    Very informational blog and explained the codes and tables well regarding RDBMS, Thank you

    Reply
  20. Balram thakur says:
    3 years ago

    The content you wrote is very informative thank you so much

    Reply
  21. Shivani Sendhav says:
    3 years ago

    Very nice and informative.

    Reply
  22. Meena Thakur says:
    3 years ago

    This blog is very Enlightening

    Reply
  23. Baldev patel says:
    3 years ago

    Useful for me , Thank you for such knowledgeable blog. It helped a lot .Love this blog. Thank for the knowledge.

    Reply
  24. Gajraj Sendhav says:
    3 years ago

    Thank you for such knowledgeable blog. It helped a lot .Love this blog. Thank for the knowledge.

    Reply
  25. Devendra Sendhav says:
    3 years ago

    The content you wrote is very informative thank you so much.

    Reply
  26. Bablu Sendhav says:
    3 years ago

    Thank you so much for such Enlightening blog..

    Reply
  27. Rajni Thakur says:
    3 years ago

    Thank you for such knowledgeable blog. It helped a lot .Love this blog. Thank for the knowledge

    Reply
  28. Garima Singh says:
    2 years ago

    Very useful blog

    Reply
  29. Ritika says:
    2 years ago

    Nice blog. gained proper knowledge

    Reply
  30. Lucky meher says:
    2 years ago

    Very usefull blog

    Reply
  31. Rajashree Pradhan says:
    2 years ago

    Very nice and informative.

    Reply
  32. Priya stock says:
    2 years ago

    Very good, there are many information regarding software.

    Reply
  33. Ranjulata Pradhan says:
    2 years ago

    Thank you so much for such Enlightening blog..

    Reply
  34. Rajesh kara says:
    2 years ago

    Thank you so much for such Enlightening blog..

    Reply
  35. Ashwika Singh says:
    2 years ago

    Nice blog. gained proper knowledge.
    Thank you for this information

    Reply
  36. Baldev patel says:
    2 years ago

    Enlightening blog 👌

    Reply
  37. Komal rathore says:
    2 years ago

    Very informational blog and explained the codes and tables well regarding RDBMS, Thank you

    Reply
  38. Patel Balram says:
    2 years ago

    . Very informative blog. Helped me a lot

    Reply
  39. Meena Nagar says:
    2 years ago

    Useful for me , thank you

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Waterfall Model(SDLC)

Waterfall Model(SDLC)

June 2, 2022
Application Programming Interface

Application Programming Interface

June 7, 2022
PHP-MYSQL Interview Questions and Answers

PHP-MYSQL Interview Questions and Answers

May 26, 2022
Artificial Intelligence

Artificial Intelligence

June 11, 2022
Waterfall Model(SDLC)

Waterfall Model(SDLC)

95
Artificial Intelligence

Artificial Intelligence

55
Application Programming Interface

Application Programming Interface

50
PHP-MYSQL Interview Questions and Answers

PHP-MYSQL Interview Questions and Answers

47
Maximizing Performance Testing Efficiency with JMeter

Maximizing Performance Testing Efficiency with JMeter

June 2, 2023
Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

May 31, 2023
Yii Framework: Turbocharge Your Web Development Projects Like Never Before

Yii Framework: Turbocharge Your Web Development Projects Like Never Before

May 27, 2023
Understanding PostgreSQL

Understanding PostgreSQL

May 24, 2023

Recent News

Maximizing Performance Testing Efficiency with JMeter

Maximizing Performance Testing Efficiency with JMeter

June 2, 2023
Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

May 31, 2023
Yii Framework: Turbocharge Your Web Development Projects Like Never Before

Yii Framework: Turbocharge Your Web Development Projects Like Never Before

May 27, 2023
Understanding PostgreSQL

Understanding PostgreSQL

May 24, 2023
TETRALEARN

Tetralearn Blog section is dedicated to Programmers, Designers and Technocrats for latest news, skills & inventions.

Browse by Category

  • Apps
  • Database Tutorial
  • Digital Marketing
  • IT Events
  • Laravel
  • Mobile Apps
  • PHP
  • Programming
  • Programming
  • Projects
  • Python
  • Science
  • Technology
  • Uncategorized
  • Web Applications

Recent News

Maximizing Performance Testing Efficiency with JMeter

Maximizing Performance Testing Efficiency with JMeter

June 2, 2023
Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

Building Robust Web Applications with CakePHP: An In-Depth Look into its Features

May 31, 2023
  • About
  • Privacy & Policy
  • Contact

© 2022, Copyrights Reserved. Powered By Tetralance

No Result
View All Result

© 2022, Copyrights Reserved. Powered By Tetralance