title: MySQL Complex Join - 4 Tables with multiple conditions
body: <p>I need help creating a complex SQL query that is a little beyond my rather basic knowledge... I would greatly appreciate anyone's help!</p>
  
  <p>See below for database structure. The bold row represents the tables; below are the relevant fields for each table.</p>
  
  <p>I included below the desired output fields as well as conditions for the query.</p>
  
  <h2><strong>Database Structure</strong></h2>
  
  <p><strong>custom_fields_data...........sales_listings.........sales.........listings</strong></p>
  
  <p>........owner_id.........   .................listing_id.......... buyer_id...........id</p>
  
  <p>.........field_id...............................sale_id..................id.............name</p>
  
  <p>..........value..............................created_at             </p>
  
  <h2><strong>Database relationships:</strong></h2>
  
  <p><strong>custom_fields_data</strong>.owner_id = <strong>sales_listings</strong>.listing_id = <strong>listings</strong>.id</p>
  
  <p><strong>sales_listings</strong>.sale_id = <strong>sales</strong>.id</p>
  
  <h2><strong>Conditions:</strong></h2>
  
  <p><strong>custom_fields</strong>_data.field_id = 4<br>
  <strong>sales</strong>.buyer_id = 12, 20, 21 or 30                       </p>
  
  <h2><strong>Desired output:</strong></h2>
  
  <p><strong>listings</strong>.id<br>
  <strong>listings</strong>.name<br>
  <strong>custom_fields_data</strong>.value<br>
  <strong>sales_listings</strong>.created_at                       </p>
  
  <p>Thank you, I really appreciate all your help.</p>