Why Query is returning empty array?

you may need to wrap $slug in quotes

$course = $wpdb->get_results( "SELECT * FROM wp_posts where post_name="$slug"" );