The Awk Programming Language[1], by Aho, Kernighan and Weinberger, has a whole chapter on using Awk as a relational database engine. (They implement a small query language in Awk itself.) It's also a great book period.
(You made me curious: there are used copies at Amazon starting at around $6.00[1].)
[1] http://www.amazon.com/gp/offer-listing/020107981X/ref=dp_olp...
http://www.catonmat.net/blog/awk-book/
It teaches Awk through many practical examples, so called one-liners, that are small and short programs that just do one task. Such as joining lines, printing lines matching a pattern, summing up numbers on lines, converting text, etc.