learn to run wpdb class

Arbitrary SQL query can be run via wpdb by using get_results() method:

$results = $wpdb->get_results( $query );

You can work through documentation for wpdb at Codex to gain basic understanding of how it works.