Fixed SQL query for public view

Fixes #324