多个INNER JOIN打破了查询

时间:2016-01-29 17:46:38

标签: php

我尝试加入多个表格,让我用我的查询代码示例更好地解释一下:

private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LoadCombo();
            dpFrom.SelectedDateChanged += new SelectionChangedEventHandler(this.dp_SelectedDateChanged);

        }

private void dp_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
   // reset label;                    
}

现在查询返回的错误是:

  

string(226)"您的SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在桌面上使用' INNER JOIN table_roles on table_roles.id = table_users.id_roles INNER JOIN表'在第1行"

查询有什么问题?

2 个答案:

答案 0 :(得分:2)

您的查询中有3个WHERE子句,只有1个有效,并且应该在FROMINNER JOIN子句之后。 WHERE子句中的所有条件都应该用AND子句(在此查询中)分隔。

if($stmt = $this->db->prepare("SELECT table_users.id AS user_id, table_users.email AS user_email, table_users.GUID as user_guid, "
    . "table_roles.slug AS role_slug, table_user_settings.username, table_users.id_roles, "
    . "table_users.first_name, table_users.last_name, table_users.mobile_number, table_users.phone_number, "
    . "table_users.address, table_users.city, table_users.state, table_users.zip_code, table_users.notes "
    . "FROM table_users "
    . "INNER JOIN table_roles ON table_roles.id = table_users.id_roles "
    . "INNER JOIN table_user_settings ON table_user_settings.GUID = table_user.GUID "
    . "WHERE table_users.data = 0 AND "
    . "table_user_settings.username = ? AND "
    . "table_user_settings.password = ? "))

您可能想要查看MySql doc中的有效SQL语法:http://dev.mysql.com/doc/refman/5.7/en/select.html

答案 1 :(得分:0)

您的查询中存在语法错误: def index: Action { val html: String = // render some action here } 这应该在WHERE table_users.data = 0

之后
JOIN