Good morning! It's the following ... I have these 2 tables in my postgresql database:
tipos_risco
--id
--nome
agentes_risco
--id
--nome
--id_tipo_risco (foreign key)
The problem is that I am not able to extract the data from them together, since both have the columns id
and nome
, then that error when I search:
QueryException in Connection.php line 651:
SQLSTATE[42702]: Ambiguous column: 7 ERROR: column reference "nome" is ambiguous
LINE 1: ...sco"."id" = "agentes_risco"."id_tipo_risco" where "nome" ILI...
^ (SQL: select count(*) as aggregate from "agentes_risco" left join "tipos_risco" on "tipos_risco"."id" = "agentes_risco"."id_tipo_risco" where "nome" ILIKE %frio%)
and this:
PDOException in Connection.php line 321:
SQLSTATE[42702]: Ambiguous column: 7 ERROR: column reference "nome" is ambiguous
LINE 1: ...sco"."id" = "agentes_risco"."id_tipo_risco" where "nome" ILI...
This is the query for my search function:
return DB::table('agentes_risco')
->leftJoin('tipos_risco', 'tipos_risco.id', '=', 'agentes_risco.id_tipo_risco')
->where('nome', 'ILIKE', '%'.$busca.'%')
->select('agentes_risco.*','tipos_risco.*')
->orderBy('id', 'asc')
->paginate(10);
How can I resolve this?