Selecting data from more than 2 tables or three tables using mysql joining

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”

idtitlecategory_idauthor_id
1Post title one11
2Post title two22
3Post title three12
4Post title four21

Table one “category”

idcat_name
1category one
2category two

Table one “users”

iduser_name
1user one
2user two

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

idtitlecat_nameuser_name
1Post title onecategory oneuser one
2Post title twocategory twouser two
3Post title threecategory oneuser two
4Post title fourcategory twouser one

Leave a Reply

Related Posts: You may like

comma separated values in mysql query

SQL statement to retrieve names beginning with A

Php pdo prepared statements select insert update queries

php pdo queries statements select insert update delete

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.