A course in data structures and algorithms is the best place to start. MIT has free materials available here. This is assuming you want to actually be good at creating SQL code which is efficient =) ...