ronaldo cr7
ronaldo cr7

Reputation: 17

How to Join multiple tables?

I tried this query for two tables and it worked, but if I want to do it for many tables how it is done?

cmd.CommandText = "SELECT *  FROM assignments 
                   inner join Customers on assignments.Customer_ID = customers.Customer_ID";
//assignments and customers are tables

Upvotes: 0

Views: 1820

Answers (4)

Sarang
Sarang

Reputation: 784

May be this will help you

SELECT * FROM assignments AS a, customers AS c WHERE a.Customer_ID = c.Customer_ID;

Upvotes: 0

Alekhya Vemavarapu
Alekhya Vemavarapu

Reputation: 1155

Consider agents,customer,orders to be your tables & you gotta join them.

SELECT 
    a.ord_num,
    b.cust_name,
    a.cust_code,  
    c.agent_code,
    b.cust_city  
FROM agents c, customer b, orders a  
WHERE b.cust_city = c.working_area  
    AND a.cust_code = b.cust_code  
    AND a.agent_code = c.agent_code;  

Regards!

Upvotes: 1

sheshadri
sheshadri

Reputation: 1217

Here I am giving one example. You can create queries like this one:

select 
    * 
from tblA a 
     inner join tblB b 
         on a.id = b.id 
     inner join tblC 
         on a.id = c.id 
     inner join tblD 
         on a.id = d.id 

Upvotes: 1

z0mbi3
z0mbi3

Reputation: 346

If you are using SQL management studio, right click and select "Design Query in Editor". This is the easiest way to join your tables (it's visual)

Upvotes: 0

Related Questions