Join multiple tables

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2007
Posts: 23
Reputation: mustoora is an unknown quantity at this point 
Solved Threads: 0
mustoora mustoora is offline Offline
Newbie Poster

Join multiple tables

 
0
  #1
Aug 18th, 2007
Hi there.
i'm having trouble joining tables. I'm using Access database. Initially, i have 2 tables called thresholdTable and Configuration. In the thresholdTable, there's a column called 'Config' and i've linked it to a column called 'Confuguration' from the Configuration table. Right now everything's working. However, i added another table, Consistency. I have a column in thresholdTable called 'Consistency' and i have to link it to 'Consistency' column from the Consistency table. How do i join 3 tables? Here's my codes:

Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String

con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Sowmya.mdb;Jet OLEDB:Database Password=geez"


con.Open()

sql = "SELECT * FROM thresholdTable INNER JOIN Configuration ON Configuration.Configuration = thresholdTable.Config"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "Sowmya")


con.Close()
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Join multiple tables

 
0
  #2
Aug 18th, 2007
You can chain joins together and the next join works on the result of the last join.
  1. SELECT *
  2. FROM thresholdTable INNER JOIN Configuration
  3. ON Configuration.Configuration = thresholdTable.Config INNER JOIN Consistency
  4. ON Consistency.Consistency = thresholdTable.Consistency;
The intermediate table that you join Consistency to is the result of joining thresholdTable and Configuration. If you wrap it in parentheses it's like this guy.
  1. ((a INNER JOIN b ON a.col = b.col) INNER JOIN c ON c.col = a.col);
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: mustoora is an unknown quantity at this point 
Solved Threads: 0
mustoora mustoora is offline Offline
Newbie Poster

Re: Join multiple tables

 
0
  #3
Aug 18th, 2007
I tried chain joins them together but i get an error. It says "Syntax error (missing operator) in query expression 'Configuration.Configuration = thresholdTable.Config INNER JOIN consistency ON consistency.consistency = thresholdTable.Consistency"
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Join multiple tables

 
0
  #4
Aug 18th, 2007
Hi,

check this:

sql = "SELECT T.* FROM thresholdTable T, Configuration C Where  C.Configuration = T.Config"

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: mustoora is an unknown quantity at this point 
Solved Threads: 0
mustoora mustoora is offline Offline
Newbie Poster

Re: Join multiple tables

 
0
  #5
Aug 19th, 2007
Then what about the consistency table? I also need to link the 'Consistency' column from thresholdTable to 'consistency' column from consistency table.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Join multiple tables

 
0
  #6
Aug 19th, 2007
Hi,

Then give one more condition in where:

sql = "SELECT T.* FROM thresholdTable T, Configuration C Where  C.Configuration = T.Config And C.Consistency = T.Consistency"

u can give any number of equal conditions..

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Join multiple tables

 
0
  #7
Aug 19th, 2007
Hi,

In case u have one more table, include that also in SQL Statement and give appropriate links..

Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: mustoora is an unknown quantity at this point 
Solved Threads: 0
mustoora mustoora is offline Offline
Newbie Poster

Re: Join multiple tables

 
0
  #8
Aug 19th, 2007
Hi..
I'm still facing some errors. It says No value given for one or more required parameters. By the way, my 'consistency' column is not from Configuration table. It's from another table called consistency. So actually i have 3 tables, thresholdTable, Configuration and consistency.

The relationship is like this:
Configuration.Configuration = thresholdTable.config,
consistency.consistency = thresholdTable.Consistency
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: Join multiple tables

 
0
  #9
Aug 19th, 2007
Hi,

Post the whole SQL Statement here. Such error occur when u have Mis-Spelled the Column Or Table Name.
I noticed it now Remove the Comma in the Relationship and give AND there. Check This:

Where Configuration.Configuration = thresholdTable.config And 
consistency.consistency = thresholdTable.Consistency
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 23
Reputation: mustoora is an unknown quantity at this point 
Solved Threads: 0
mustoora mustoora is offline Offline
Newbie Poster

Re: Join multiple tables

 
0
  #10
Aug 20th, 2007
Hi..
i'm still having errors. I added this statement:

sql = "SELECT * FROM thresholdTable Where Configuration.Configuration = thresholdTable.config And consistency.consistency = thresholdTable.Consistency"

It highlighted this code and says that no value is given for one or more required parameters.

Me.ThresholdTableTableAdapter.Fill(Me.SowmyaDataSet.thresholdTable)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC