Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Active Record - Table Alias
#1

[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?
#2

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

[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();
#4

[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.
#5

[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!




Theme © iAndrew 2016 - Forum software by © MyBB