Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to make a 3 joined taqlbe and did this:
VB
daSector = New OleDbDataAdapter("SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation " &
                              "FROM (Sector INNER JOIN Association ON Sector.SectorID=Association.SectorID)" &
                              "INNER JOIN Company ON Company.AssociationID = Association.AssociationID", con)



It worked as I was expecting it to work but when I added another table.
These set codes of sets below.
VB
daSector = New OleDbDataAdapter("SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation,Product.ProductDesc,Product.RawMatDesc " & 
                            "FROM (Sector INNER JOIN Association ON Sector.SectorID=Association.SectorID)" & 
                            "(INNER JOIN Company ON Company.AssociationID = Association.AssociationID) " & 
                            " INNER JOIN Product ON Product.CompanyID = Company.CompanyID  ", con)


It stops working and pops out an error that says something is wrong with the FROM clause. So as you can see there, I put the 2nd inner join into parenthesis but still no use and pops out the FROM clause error again. Can someone please point out what am I lacking here?
Posted
Updated 19-Jul-15 22:18pm
v2

Joining more than two tables is the same as with two tables so you need to have some mistake in the table names, column names or syntax.

Typically the tables are listed in the ON clause in the same order as they are in the FROM clause. Also I don't see any need for the parenthesis.

So simply try something like
SQL
SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation,Product.ProductDesc,Product.RawMatDesc 
FROM Sector 
     INNER JOIN Association ON Sector.SectorID=Association.SectorID
     INNER JOIN Company ON Association.AssociationID = Company.AssociationID
     INNER JOIN Product ON Company.CompanyID = Product.CompanyID 
 
Share this answer
 
Comments
Jake Robert 20-Jul-15 4:36am    
But when I remove the parenthesis it pops out an error like this:
Syntax error (missing operator) in query expression 'Sector.SectorID=Association.SectorID INNER JOIN Company ON Association.AssociationID=Company.AssociationI'.

Maybe the problem is really how I will put the parenthesis for the 4th join. I have followed your solution though. It pops out the same result as above.
I made it work by coating another parenthesis

VB
daSector = New OleDbDataAdapter("SELECT Sector.SectorName, Association.AssociationName, Company.CompanyName, Company.CompanyLocation, Product.ProductDesc, Product.RawMatDesc " &
"FROM ((Sector " &
"INNER JOIN Association ON Sector.SectorID=Association.SectorID) " &
"INNER JOIN Company ON Association.AssociationID=Company.AssociationID) " &
"INNER JOIN Product ON Company.CompanyID=Product.CompanyID ", con)


Thanks for your suggestion though :) If not for you I would not realize it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900