0

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

4 Answers4

1

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!

veljasije
  • 6,722
  • 12
  • 48
  • 79
Alekhya Vemavarapu
  • 1,145
  • 1
  • 10
  • 26
1

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 
veljasije
  • 6,722
  • 12
  • 48
  • 79
sheshadri
  • 1,207
  • 9
  • 21
0

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)

z0mbi3
  • 336
  • 4
  • 14
0

May be this will help you

SELECT * FROM assignments AS a, customers AS c WHERE a.Customer_ID = c.Customer_ID;
Sarang
  • 754
  • 3
  • 9
  • 24