mysql连接具有相同列名的多个表| Codeigniter |

时间:2016-06-06 06:53:38

标签: php mysql codeigniter join

我正在制作管理页面,我想加入多个表格。 到目前为止还有效。

但是现在我想加入另一个表,但它与我在其他连接查询中使用的列名相同。

是否有一种方法可以让它无需更改列名称

这是我现在的代码:

$this->codeignitercrud->table ( 'user_to_designment' );
$this->codeignitercrud->tableAlias ( 'Users to designment' ); 
$this->codeignitercrud->join ( 'right', 'users', 'user_to_designment.user_id = users.user_id');
$this->codeignitercrud->join ( 'right', 'user_profiles', 'users.username = user_profiles.email');
$this->codeignitercrud->join ( 'right', 'designments', 'user_to_designment.designment_id = designments.designment_id');
// This one makes a problem now -- >$this->codeignitercrud->join ( 'right', 'inspiration', 'users.user_id = inspiration.user_id');

$this->codeignitercrud->addNoCol ( true );


$this->codeignitercrud->cols ( 'designment_id');
$this->codeignitercrud->cols ( 'designments.title');
$this->codeignitercrud->cols ( 'users.username');
$this->codeignitercrud->cols ( 'user_profiles.first_name');
$this->codeignitercrud->cols ( 'user_profiles.last_name');

我必须得到列的所有字段。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以选择声明table.fieldname,并在查询中写入“table.fieldname AS newname”...这是检索不同表的相同列名的方法。