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”

id title category_id author_id
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”

id cat_name
1 category one
2 category two

Table one “users”

id user_name
1 user one
2 user 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

id title cat_name user_name
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

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

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.