title: how to create a nested query using sqldf
body: <p>Im trying to write a nested query using sqldf. the dataset is 'contact_fb ' . i am trying to only take rows without clubmahindra and  distinct names which are in column 'from_name' and then left join with the 'contact_fb ' to get all the info in the other columns. this is giving not the result i want.</p>
  
  <pre><code>contact_fb =structure(list(X = 1:6, from_name = c("Club Mahindra", "Club Mahindra","pinto", "valencia", "valencia", "Club Mahindra"), type = structure(c(2L, 2L, 2L, 1L, 1L, 2L), .Label = c("link","photo", "status", "video"), class = "factor")), .Names = c("X","from_name", "type"), row.names = c(NA, 6L), class = "data.frame")
  </code></pre>
  
  <p>my attempt at this is </p>
  
  <pre><code>names_cm=sqldf("select t1.from_name, t2.* from (select distinct from_name from  contact_fb where from_name!='Club Mahindra') as t1 left join  ( select * from contact_fb ) as t2 on t1.from_name=t2.t1.from_name")
  </code></pre>
  
  <p>i could get it finally through </p>
  
  <pre><code>sqldf("select distinct(t1.from_name),t2.* from df t1 left join df t2 on (t1.from_name=t2.from_name) where t1.from_name!='Club Mahindra' group by t1.from_name")
  </code></pre>
  
  <p>i dont understand where im going wrong. could i still get it through my way?</p>
  
  <p>the output is </p>
  
  <pre><code>3   Pinto   photo
  4   valencia    link
  </code></pre>