To display in a CGridView, I suggest to use my RelatedSearchBehavior extension . Get the demo, check it out, make some changes to get the feel of it and then apply to your case.
There are many ways to see the SQL statements, all use the log routes. I use http://www.yiiframework.com/extension/yiidebugtb/ to see the requests in my browser in a not too intrusive and efficient way.
I guess that we are back to the initial issue: your relation is a ‘HAS_MANY’ which means that ‘$data->relationName’ returns an array so you can not do ‘->secondtablecolumn’ on the array, you must loop on it.
If you want to show all marks, use the marks as the base model and determine the student for each mark in your gridview. Then you’ll have a ‘HAS_ONE’ relation.