Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

SQL | SELECT data from Multiple Tables

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Below statement could be used to get data from multiple tables, so, we need to use join to get data from multiple tables.

Syntax :

SELECT tablenmae1.colunmname, tablename2.columnnmae    
FROM tablenmae1  
JOIN tablename2  
ON tablenmae1.colunmnam = tablename2.columnnmae
ORDER BY columnname;  

Let us take three tables, two tables of customers named Geeks1, Geeks2 and Geeks3.

Geeks1 table :

IDFirstName
1Nisha
2Manoj
3Pooja

Geeks2 table :

IDLastName
1Gupta
2Desai
3Kumari

Geeks3 table :

GIDPIDAsset
1P1Laptop
2P2Desktop
3P3Laptop
4P4None

Example to select from multiple tables :

SELECT Geeks3.GID, Geeks3.PID, 
       Geeks3.Asset, Geeks1.FirstName, 
       Geeks2.LastName  
FROM Geeks3
LEFT JOIN Geeks1 
ON Geeks3.GID = Geeks1.ID
LEFT JOIN Geeks2 
ON Geeks3.GID = Geeks2.ID  

Output :

GIDPIDAssetFirstNameLastName
1P1LaptopNishaGupta
2P2DesktopManojDesai
3P3LaptopPoojaKumari
4P4NoneNULLNULL

My Personal Notes arrow_drop_up
Last Updated : 17 Aug, 2020
Like Article
Save Article
Similar Reads