Header Ads

How to join more three table in mysql

MySQL is a free open-source relational database management system (RDBMS) that supports SQL (Structured Query Language). It was originally developed by Oracle Corporation but has since been released under the GPL license.MySQL is widely used in many different areas including web hosting, e-commerce, online publishing, social networking, and software configuration management. beside Mysql you can use  

1. MariaDB

MariaDB is a community-developed fork of MySQL. It is based on the same code base but is licensed under the GNU General Public License (GPL) version 2.0.

2. PostgreSQL

PostgreSQL is a powerful object-relational database management system (ORDBMS) that supports ACID transactions and foreign keys. It is a commercial product from PostgreSQL Global Development Group (PGDG), formerly known as Postgres Software Inc.

If you want to select data from many tables We need to use a join table relational database
this tutorial will show you how to join more than three tables for example below. 



1. tb_orders
2.tb_order_detail
3. tb_customer
4. tb_products 

Query


SELECT
 o.oid,
 p.pname,
 od.quantity,
 od.unit_price
FROM
 tb_orders o
LEFT JOIN tb_order_detail od ON od.oid = o.oid
LEFT JOIN tb_customers c ON c.cusid = o.cid
LEFT JOIN tb_products p ON p.pid = od.pid

The provided code is a SQL query written in the SELECT statement format. This query retrieves data from multiple tables: tb_orders, tb_order_detail, tb_customers, and tb_products. The query joins these tables together to gather specific information related to orders, order details, customers, and products.


No comments:

Powered by Blogger.