A SQL SELECT-like function