SQL Tutorial

SQL SELECT from Multiple Tables

SQL SELECT from Multiple Tables
SQL SELECT from Multiple Tables

SQL SELECT from Multiple Tables

When working with relational databases, retrieving data from multiple tables is a common requirement. The SELECT statement lets us fetch fields from different tables by using JOIN queries to establish relationships between them.

Complete Python Course with Advance topics:-
SQL Tutorial:-

Example: Two Tables with INNER JOIN

SELECT orders.order_id, suppliers.company_name
FROM suppliers
INNER JOIN orders ON suppliers.supplier_id = orders.supplier_id
ORDER BY order_id;

Example: Three Tables with LEFT JOIN

Suppose we have client1, client2, and a sales table. We can combine all three:

SELECT s.sale_id, s.client_id, s.product_name,
       c1.first_name, c2.last_name
FROM sales AS s
LEFT JOIN client1 AS c1 ON s.client_id = c1.client_id
LEFT JOIN client2 AS c2 ON s.client_id = c2.client_id;
sale_idclient_idproductfirst_namelast_name
501101LaptopAliceJohnson
502102SmartphoneBobSmith
503C101PrinterNULLNULL

Explanation

The LEFT JOIN ensures all rows from the sales table appear, even when there is no match in client1 or client2 (returning NULL for missing values).

Selecting Without JOIN (Comma Syntax)

You can also query multiple tables using the older comma syntax with a WHERE condition, though explicit JOINs are clearer and preferred:

SELECT o.order_id, s.company_name
FROM orders o, suppliers s
WHERE o.supplier_id = s.supplier_id;

Download New Real Time Projects:- Click here
Complete Advance AI topics:-

Conclusion

Fetching data from multiple tables using JOINs is essential for combining and analyzing data from different sources. With proper relationships and join conditions, you get meaningful insights easily. For more tutorials, stay tuned to .

sql select multiple tables without join
select data from two tables in sql with where clause
sql select from multiple tables with conditions
select data from multiple tables in single query
sql join multiple tables
sql select from multiple tables example
left join multiple tables
sql select multiple tables w3schools

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

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

Chat with us