title: SQL Query in NHibernate diction
body: <p>I have a SQL Query which works in SQL Management Studio:</p>
  
  <p>Select Id 
  From table t
  Where t.Date=
    (Select Max(Date)
     From (
        Select * 
        From table where ReferenceId = xy) u)</p>
  
  <p>Reason is, from all entries with a certain foreign key, I want to receive the one with
  the highest date.</p>
  
  <p>I tried to reform this Query for use in NHibernate, and I got</p>
  
  <pre><code>IQuery query = session.CreateQuery(String.Format(
              @"Select t.Id  
              From table t
              Where t.Date =
                  (Select Max(Date)
                  From (Select * 
                        From table t where t.ReferenceItem.Id = " + item.ReferenceItem.Id + ")u)"));
  </code></pre>
  
  <p>I get the error message: "In expected"</p>
  
  <p>How do I have to form the NHibernate query? What does the "In" mean?</p>