-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem whith SELECT DISTINCT
PostPosted: Wed Jan 23, 2008 4:32 am 
Newbie

Joined: Wed Jan 23, 2008 4:23 am
Posts: 3
Hi

i want to make a distinct request on a table :

Code:
public IList GetAllNames()
      {
            string sql = "SELECT DISTINCT(Name) FROM myTable;";           
            ISQLQuery sqlQuery = this.Session.CreateSQLQuery(sql);
            sqlQuery.AddScalar("Name", NHibernateUtil.String);
            IList listOfNames = sqlQuery.List();
            return listOfNames;
      }


The return list have the correct number of record but all of the entries are null !

I have test with :

Code:
public IList GetAllNames()
      {
            string sql = "SELECT Name FROM myTable;";           
            ISQLQuery sqlQuery = this.Session.CreateSQLQuery(sql);
            sqlQuery.AddScalar("Name", NHibernateUtil.String);
            IList listOfNames = sqlQuery.List();
            return listOfNames;
      }


and it works !

thx for your help


Top
 Profile  
 
 Post subject: Problem whith SELECT DISTINCT
PostPosted: Wed Jan 23, 2008 8:15 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi Seth77,

You haven't mentioned which dialect/driver you're using.

I suspect that the column might need aliased, so you could try:

Code:

string sql = "SELECT DISTINCT(Name) Name FROM myTable;";



Regards,
Richard


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.