Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I have three tables and each table has a common attribute named "indate" and whenever i"m trying to join three tables using the following query it gives me an error "Syntax error in FROM clause". please solve my problem. Thanks.....
C#
OleDbCommand cm = new OleDbCommand("SELECT payment.indate,payment.opening_balance,payment.purpose,payment.amount,income.indate,income.opening_balance,income.purpose,income.amount,bank_dep.indate,bank_dep.balance_opening,bank_dep.bank,bank_dep.amount FROM payment INNER JOIN income,bank_dep ON payment.indate=income.indate=bank_dep.indate",cn);


[Edit]Code block added[/Edit]
Posted
Updated 19-Feb-13 6:56am
v2
Comments
Member 11649391 30-May-15 2:03am    
I have join 5 tables how to use inner join query for joining five tables in c# using ms access database?
this is my code
try
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\BS(CS)-6A\BS(CS)-6A\Database Managment System\Student Managment Project\School_Database\School_Managment_System.accdb;
Persist Security Info=False;";
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
// string query = "select s.std_id, s.std_name, s.std_fname, s.std_phone, s.std_address, f.fee_paid, f.balance, f.fee_month, f.fee_year from std_info s join std_fees f on s.std_id = f.std_id";
string query = @"select *from (std_info inner join std_fees on std_info.std_id = std_fees.std_id), (inner join fees on fees.fee_id = std_fees.fee_id),(inner join class on class.class_id = fees.class_id)";
cmd.CommandText = query;

OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
dataGrid1.DataSource = dt;

conn.Close();
}
catch (Exception ex) {
MessageBox.Show("Error" + ex);
}

1 solution

FROM payment INNER JOIN income,bank_dep


You can have more tables in FROM, like: FROM payment,income,bank_dep, but you can't have other than one single table after JOIN, and you have two. And you never can have an operation like a=b=c, but you have You need to split the statement across multiple joins:
SQL
SELECT payment.indate,payment.opening_balance,payment.purpose,payment.amount,income.indate,income.opening_balance,income.purpose,income.amount,bank_dep.indate,bank_dep.balance_opening,bank_dep.bank,bank_dep.amount 
FROM (payment 
INNER JOIN income ON payment.indate=income.indate)
INNER JOIN bank_dep ON income.indate=bank_dep.indate
 
Share this answer
 
v2
Comments
Maciej Los 19-Feb-13 13:21pm    
+5!
Chiklu.Soumya 19-Feb-13 13:40pm    
it gives an error "syntax error(missing operator) in query expression 'payment.indate=income.indate INNER JOIN bank_dep on income.indate=bank_dep.indate"
Zoltán Zörgő 19-Feb-13 15:44pm    
Sorry, Access is non-standard, it requires some parenthesis. See updated query.
Chiklu.Soumya 19-Feb-13 22:08pm    
Thanks A lot. Now it's working fine.
Zoltán Zörgő 20-Feb-13 3:26am    
You are welcome. Feel free to accept my answer.

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



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