1

How do I do something similar in Views with the below SQL query?

select nid,
title AS title1,
type AS node_type,
(select title from node,
field_data_field_node_reference_id
where
node.nid = field_data_field_node_reference_id.field_node_reference_id_target_id
AND
field_data_field_node_reference_id.entity_id = 1)
AS title2,
(select nid from node,
field_data_field_node_reference_id
where
node.nid = field_data_field_node_reference_id.field_node_reference_id_target_id
AND
field_data_field_node_reference_id.entity_id = 1)
AS nid2
from node
where nid=1;

The output in MySQL would be:

nid | title1     | node_type |   title2        | nid2
1   | Some Title | MyNode    |   Another Title | 69

As you can see, they share a relationship by a field called 'field_node_reference_id_target_id'. Both values, 'title1' and 'title2', are from the same table called 'node'. I would like to avoid writing my own SQL queries, so is there a way to get views to display a similar output (e.g. node titles in the same row that share a relationship)?

3

Yes, simply

  1. Add the field relationship your View
  2. Add the required fields to the view
  3. On the relevant field configuration form, select the relationship to use.

For example:

  • "Title" ( no relationship ) to select from base table and
  • "Title" ( with relationship ) to select from related data.
  • 1
    Wow! I did not realize you could use the same field multiple times. This worked perfectly. THANK YOU! – user785179 Jan 5 '13 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.