-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Closed
Description
When using the following query:
$tags = DB::table('tag')
->leftJoin('cursus_tag', 'cursus_tag.tag_id', '=', 'tag.id')
->leftJoin('cursus', 'cursus.id', '=', 'cursus_tag.cursus_id')
->whereIn('cursus.curriculumdeel_id', array($cd->id, $cd2->id))
->lists('tag.name');I get the error "Column 'name' in field list is ambiguous".
The SQL query (mySql) is this one:
select `name` from `tag`
left join `cursus_tag` on `cursus_tag`.`tag_id` = `tag`.`id`
left join `cursus` on `cursus`.`id` = `cursus_tag`.`cursus_id`
where `cursus`.`curriculumdeel_id` in (3, 1))The problem being that the select statement should be select 'tag.name' from 'tag'.
A workaround is to change the query to this:
$tags = DB::table('tag')
->select('tag.name')
->leftJoin('cursus_tag', 'cursus_tag.tag_id', '=', 'tag.id')
->leftJoin('cursus', 'cursus.id', '=', 'cursus_tag.cursus_id')
->whereIn('cursus.curriculumdeel_id', array($cd->id, $cd2->id))
->lists('tag.name');Metadata
Metadata
Assignees
Labels
No labels