How Can I Put Meta_Compare in the Database-Query?

Yes, I know that this can easily be done with built in wp_query but I need this in Wpdb query. I have a custom field and I need to display posts where this field does not exist. By the way can I get the same results with a normal wp_query? The code is below:

 $posts = $wpdb->get_results( $wpdb->prepare(
 "SELECT ID, post_title, post_name FROM wp_posts
 INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)
 INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
 INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id =      wp_term_taxonomy.term_taxonomy_id)
 WHERE
 wp_term_taxonomy.term_id = 1
 AND wp_postmeta.meta_key = 'my_meta_key'
 AND META_COMPARE = 'NOT EXISTS'
 AND post_type = 'post'
 AND post_status = 'publish' 
 AND post_title LIKE %s ORDER BY post_title ASC",
 $letter . '%'
 ));

Related posts