Welcome Guest, Not a member yet? Register   Sign In
Unknown column 'xxx' in 'on clause'
#3

[eluser]ibnclaudius[/eluser]
Quote:Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`this->users_table` . users.id AND sessions.token = $this->users_table . 8a4668b' at line 3

Code:
SELECT `users`.`id` AS id, `users`.`name` AS name, `users`.`email` AS email, `users`.`type` AS type
FROM (`users`)
INNER JOIN `sessions` ON `sessions`.`user_id` = $`this->users_table` . users.id
AND sessions.token = $this->users_table . 8a4668b91e275e020c54444ae9e5cbbc81fba13a
WHERE `sessions`.`token` = '8a4668b91e275e020c54444ae9e5cbbc81fba13a'

I can make it work, like this:

Code:
$query = $this->db->select($this->users_table . '.id AS id, ' . $this->users_table . '.name AS name, ' . $this->users_table . '.email AS email, ' . $this->users_table . '.type AS type')
    ->from($this->users_table)
    ->join($this->sessions_table, $this->sessions_table . '.user_id = ' . $this->users_table . '.id', 'INNER')
    ->where($this->sessions_table . '.token', $token)
    ->get();

But I want to put the where($this->sessions_table . '.token', $token) inside the join clause, because I have another $query like this and works.

Code:
$query = $this->db->select($this->schools_table . '.id AS id, ' . $this->schools_table . '.name AS name')
    ->from($this->schools_table)
    ->join($this->users_schools_table, $this->users_schools_table . '.school_id = ' . $this->schools_table . '.id AND ' . $this->users_schools_table . '.user_id = ' . $user_id, 'INNER')
    ->order_by($this->users_schools_table . '.created', 'DESC')
    ->limit(1)
    ->get();


Messages In This Thread
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:06 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:14 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:17 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:20 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:24 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:28 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:32 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:33 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:34 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:44 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-05-2012, 12:52 PM
Unknown column 'xxx' in 'on clause' - by El Forum - 02-06-2012, 02:05 AM



Theme © iAndrew 2016 - Forum software by © MyBB