Here i am writing mysql joining query for fetching data from three tables, Some time we looking for fetch data from more then one or two tables separately for that some developer using nested queries means query inside query but this is not right way to do this.
Here i taking three different name of tables such as 1. posts 2. users 3. category
Using that tables i am fetching data post detail, according to author id fetching name of author from users table and fetching category name from category table using category id, below is mysql joining query for fetching data from three tables.
Table one “posts”
|1||Post title one||1||1|
|2||Post title two||2||2|
|3||Post title three||1||2|
|4||Post title four||2||1|
Table one “category”
Table one “users”
MySql Joining Query
"SELECT p.id, p.title, c.cat_name, u.user_name FROM posts p INNER JOIN category c ON (c.id = p.category_id) INNER JOIN users u ON (u.id = p.author_id)"
Result/Output of mysql joining query
|1||Post title one||category one||user one|
|2||Post title two||category two||user two|
|3||Post title three||category one||user two|
|4||Post title four||category two||user one|
Author: Mukesh Jakhar
This is Mukesh Jakhar. I’m a professional web developer with 3+ years experience. I am always ready for freelance work and i am writing blogs in my free time. I love to learn new technologies and share with others.
I founded PHPKIDA in September 2015. The focus of this website to provide web development tutorials of PHP, WordPress, CodeIgniter, Jquery, MySQL, HMTL, CSS etc and sharing solution of problems which i already solved.