select query for tables

see test class file for references