帮助在SELECT语句中使用JOIN

时间:2011-04-04 20:10:31

标签: sql

我正在尝试加入TABLE_1和TABLE_2,我需要在HTML表格中使用这些字段中的每一个。我收到有关我的FROM子句的错误,但我认为涉及更多错误。

                           "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 "
                         + "WHERE TABLE_1.id = TABLE_2.id "
                         + "AND add_user = ?");

3 个答案:

答案 0 :(得分:3)

更改WHERE TABLE_1.id = TABLE_2.id AND add_user = ?

ON TABLE_1.id = TABLE_2.id WHERE add_user = ?

答案 1 :(得分:1)

试试这个,而不是:

                       "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 = ?");

答案 2 :(得分:0)

通过ON而不是

加入表格

http://www.w3schools.com/sql/sql_join_inner.asp