How to left join meta in queries [closed]

One possible solutions is use Queries in the joins instead of tables.

so the query would look something like

//read products with thumbnail and sku
  SELECT products.*, skus.sku, thumbs.thumbnail
  FROM `wp_posts` as products
  LEFT JOIN (
    SELECT posts2.ID, pm1.meta_value as sku
    FROM `wp_posts` as posts2
    LEFT JOIN `sf_postmeta` as pm1 ON posts2.ID = pm1.post_id 
    WHERE pm1.meta_key = '_sku'
  ) as skus ON products.ID = skus.ID 
  LEFT JOIN (
    SELECT posts3.ID, p1.guid as thumbnail
    FROM `wp_posts` as posts3
    LEFT JOIN `sf_postmeta` as pm2 ON posts3.ID = pm2.post_id 
    LEFT JOIN `sf_posts` as posts4 ON pm2.meta_value = posts4.ID
    WHERE  pm2.meta_key = '_thumbnail_id'
  ) as thumbs ON products.ID = thumbs.ID 
  WHERE products.post_type="product";

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)