Help using JOIN in a SELECT statement
I am trying to join TABLE_1 and TABLE_2, I need to use every one of these fields in my HTML table. I am getting an error about my FROM clause, but I believe there are more errors involved.
"SELECT "
+ "TABLE_1.id, "
+ "TABLE_1.date, "
+ "TABLE_1.location, "
+ "TABLE_1.name, "
+ "TABLE_1.status "
+ "TABLE_2.date, "
+ "TABLE_2.location, "
+ "TABLE_2.name, "
开发者_Go百科 + "TABLE_2.type "
+ "FROM SCHEMA_1.TABLE_1 JOIN SCHEMA_1.TABLE_2 "
+ "WHERE TABLE_1.id = TABLE_2.id "
+ "AND add_user = ?");
Change the WHERE TABLE_1.id = TABLE_2.id AND add_user = ?
for ON TABLE_1.id = TABLE_2.id WHERE add_user = ?
Try this, instead:
"SELECT "
+ "TABLE_1.id, "
+ "TABLE_1.date, "
+ "TABLE_1.location, "
+ "TABLE_1.name, "
+ "TABLE_1.status "
+ "TABLE_2.date, "
+ "TABLE_2.location, "
+ "TABLE_2.name, "
+ "TABLE_2.type "
+ "FROM "
+ " SCHEMA_1.TABLE_1 JOIN SCHEMA_1.TABLE_2 "
+ " ON TABLE_1.ID = TABLE_2.ID"
+ "WHERE add_user = ?");
Join the tables by ON not where
http://www.w3schools.com/sql/sql_join_inner.asp
精彩评论