Welcome Guest, Not a member yet? Register   Sign In
SQL : join with tables with same fields name (eg primary id) return invalid results
#1

Hi,

I noticed that if I build a query with 2 tables having the same name for primary key (and I guess this will be the case with any other field), the result is invalid as the id key in the resulting array contains only the id of the joined table.

This is for example the case in the documentation :


PHP Code:
$builder->db->table('blog');
$builder->select('*');
$builder->join('comments''comments.id = blogs.id');
$query $builder->get();

// Produces:
// SELECT * FROM blogs JOIN comments ON comments.id = blogs.id 



We should have 2 id keys (I know this isn't possible in php, but the name of the result array key should be blogs.id and comments.id)


Sincerly,

Fred
Reply
#2

When there is a possible confusion of fields, it is then necessary to list them all in the SELECT with the name of the table first (i think)
Reply
#3

This is in the forums here using search on How CodeIgniter join two tables to have both Id columns.

CodeIgniter Forums - How codeigniter join two tables to have both Id columns
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB