CodeIgniter Forums
[SOLVED] Active Record - Table Alias - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [SOLVED] Active Record - Table Alias (/showthread.php?tid=32330)



[SOLVED] Active Record - Table Alias - El Forum - 07-20-2010

[eluser]fszostak[/eluser]
I'm in migration of MySQL to Oracle, the code below is okay with MySQL, but with Oracle dont work.

$this->db->from("table1 t1");
$this->db->join("table2 t2", "t2.id = t1.id");

Which correct form to set table alias?


[SOLVED] Active Record - Table Alias - El Forum - 07-20-2010

[eluser]WanWizard[/eluser]
What is the error message? Table aliases are perfectly acceptable for Oracle.


[SOLVED] Active Record - Table Alias - El Forum - 07-20-2010

[eluser]fszostak[/eluser]
Thanks for reply.

I dont received specific error message, only this:

Code:
A Database Error Occurred

Error Number:

SELECT "t1"."id", "t1"."title", "t2"."name" FROM "table1" t1 JOIN "table2" t2 ON "t1"."user_id" = "t2"."id" WHERE "t1"."parent_id" = 0

My code:

Code:
$this->db->select("t1.id, t1.title, t2.name");
$this->db->from("table1 t1");
$this->db->join("table2 t2", "t1.user_id = t2.id");
$this->db->where("t1.parent_id", $parent_id);
$query = $this->db->get();
return $query->result();



[SOLVED] Active Record - Table Alias - El Forum - 07-20-2010

[eluser]WanWizard[/eluser]
Don't know why you don't get an error message.

Note that Oracle names are case sensitive when they are put between quotes, so table1 may not be called Table1 in your database.


[SOLVED] Active Record - Table Alias - El Forum - 07-20-2010

[eluser]fszostak[/eluser]
I know about case-sensitive problems, but table names and field names are okay.

I solved the problem, the alias must be in UPPERCASE.

Take a look:

Code:
$this->db->select("T1.id, T1.title, T2.name");
$this->db->from("table1 T1");
$this->db->join("table2 T2", "T1.user_id = T2.id");
$this->db->where("T1.parent_id", $parent_id);
$query = $this->db->get();
return $query->result();


Thanks!