title: Nested mysql query for customer and customer_contact table
body: <p>I have 2 tables <strong>customer</strong> and <strong>customer_contact</strong></p>
  
  <p>Here <strong>customer</strong> has basic information such as 
  <code>id (primary key), name, lastname, gender, dob, username, email, phone</code> and 
  <strong>customer_contact</strong> <em>has address details of customer</em> such as <code>id (primary key), customer_id (foreign key for customer id), name, phone, address, locality, pincode, state, city</code></p>
  
  <p>Now customer can have multiple address in customer_contact table which I want to fetch in single query with all his basic information as well, below is query</p>
  
  <pre><code>SELECT customer.name, customer.lastname, customer.gender, customer.dob, 
  customer.username, customer.email, customer.phone 
      FROM customer, (SELECT id as contact_address_id, 
          name as contact_name, 
          phone as contact_phone, 
          address as contact_address, 
          locality as contact_locality, 
          pincode as contact_pincode, 
          state as contact_state, 
          city as contact_city 
          FROM customer_contact 
          GROUP BY customer_id) customer_contact 
      WHERE customer_contact.customer_id=customer.id AND customer.id='$custId'
  </code></pre>
  
  <p>The above query is giving me "Unknown column 'customer_contact.customer_id' in 'where clause'"</p>
  
  <p>Please do suggest what's going wrong here or if any other better way to write sql query where I get basic information from one table as well as multiple contact details from another table.. </p>