I'd suggest checking out the API Examples to find this info. You need to specify the classname of the custom table and not the actual query. If you want to use your own SQL query vs. the API to generate the query, then you need to use the ConnectionHelper.ExecuteQuery()
method. You can see an example on this post.