Welcome Guest, Not a member yet? Register   Sign In
db join gives 'not unique alias' error [SOLVED]
#1

[eluser]nilsm[/eluser]
Hello,

when I do a join without assigning aliases to the table names, I get a SQL error:

Here is my CI code:

Code:
$this->db->select('user_sections.*, section_types.name AS sectionType', FALSE);
$this->db->from('user_sections');
$this->db->join('section_types', 'user_sections.typeid = section_types.id');

and here is the SQL error. See how it doubles up on table names in the 'from' part of the query? That is what is causing the error and I'm not sure why it's happening:

Code:
Not unique table/alias: 'user_sections'

SELECT user_sections.*, section_types.name AS sectionType FROM (user_sections, user_sections) JOIN section_types ON user_sections.typeid = section_types.id

I can workaround by assigning aliases to the table names in the 'from' and 'join' sections but it seems like a CI bug or perhaps a misunderstanding on my part, so was hoping there was another fix.

This code works:

Code:
$this->db->select('a.*, b.name AS sectionType', FALSE);
$this->db->from('user_sections as a');
$this->db->join('section_types as b', 'a.typeid = b.id');

Thanks - Nils


Messages In This Thread
db join gives 'not unique alias' error [SOLVED] - by El Forum - 10-14-2009, 08:34 AM
db join gives 'not unique alias' error [SOLVED] - by El Forum - 10-14-2009, 08:48 AM
db join gives 'not unique alias' error [SOLVED] - by El Forum - 10-14-2009, 09:00 AM



Theme © iAndrew 2016 - Forum software by © MyBB