views:

16

answers:

1

I have a content type appointment with a date field that references nodes of the content type person using the Nodereference module. In the content type person I added a Nodereferrer field that shows the reverse of this references (Person -> appointments).

I now want to create a view of person nodes that shows the last appointment date of that person. I can create a View of persons with a relationship to appointments that displays all appointments, but I have no idea on how to display only the most recent one.

Any ideas on how to achieve this?

+1  A: 

Personally I have not had much success with using views and node reference. It never seems to work out the relationships properly.

So my advice would be to write your own query. If you look here you can see a way to override the SQL generated by views, so you still get a lot of the goodness which comes with views.

By the way I would be very interest to see if there is a better answer than this

Jeremy French
Thanks for the idea. I'll try if I can put a query for that together, but my SQL knowledge is very limited. I'm not sure how to do a join where I only get one specific value and not all of them.
Fabian
'group by' and 'max' will help you there. Join on everything group by nid and use max to get the latest one. You can put it all in a sub query too keep everything else clean.
Jeremy French

related questions