Selecting from a column in a joined table in Views I've got two tables: {students} and {student_names}. Students is the base table, with a primary key of {students}.sid. Student names is the joined table, and has a key of {student_names}.sid.

I've defined my join in hook_views_data:

$data['students']['table']['join']['student_names'] = [
  'left_field' =&gt; 'sid',
  'field' =&gt; 'sid',
];


I want to select the given name of the student from the joined table. I've defined the field as follows (again in hook_views_data()):

$data['students']['given_name'] = [
  'title' =&gt; t('Given name'),
  'help' =&gt; t('The given (first) name of the student'),
  'field' =&gt; [
    'handler' =&gt; 'views_handler_field',
 　　'click sortable' =&gt; TRUE,
  ],
  'sort' =&gt; [
    'handler' =&gt; 'views_handler_sort',
  ],
  'filter' =&gt; [
    'handler' =&gt; 'views_handler_filter_string',
  ],
  'relationship' =&gt; [
    'base' =&gt; 'student_names',
    'field' =&gt; 'sid',
    'handler' =&gt; 'views_handler_relationship',
  ],
];


I'm getting this error:


  Column not found: 1054 Unknown column 'students.given_name' in 'field list'


How can I tell views that the column is in the {student_names} table and not the {students} table?
I solved my own issue.

I needed to expose the joined table to views as well. So on top of setting up $data['students'], I also needed to set up $data['student_names'], with a join back to the original table. Here is my hook_views_data() in its entirity:

$data['student_names']['table'] = [
  'group' =&gt; t('Student'),
  'base' =&gt; [
    'field' =&gt; 'sid',
    'title' =&gt; t('Student'),
  ],
  'join' =&gt; [
    'students' =&gt; [
      'left_field' =&gt; 'sid',
      'field' =&gt; 'sid',
      'type' =&gt; 'inner',
    ],
  ],
];

$data['student_names']['given_name'] = [
  'title' =&gt; t('Given name'),
  'help' =&gt; t('The given (first) name of the student'),
  'field' =&gt; [
    'handler' =&gt; 'views_handler_field',
    'click sortable' =&gt; TRUE,
  ],
];

return $data;