Wrapping up query

2 views
Skip to first unread message

Nikhil Ketkar

unread,
Feb 15, 2012, 1:20:28 AM2/15/12
to nhu...@googlegroups.com
Hi,

I am stuck with a problem where I need to do something like below in nhibernate,

select rs.FirstName, rs.name, COUNT(rs.id) from
(
    select firstname, lastname, (select id from users where userid = 12345') as id    
    from person p
) rs
group by rs.firstname, rs.name

How I can achieve this in nhibernate?

Thanks,
NK

Itzik Saban

unread,
Feb 15, 2012, 8:16:29 AM2/15/12
to nhu...@googlegroups.com
Subqueries in HQL.

בתאריך 15 בפברואר 2012 08:20, מאת Nikhil Ketkar <nmke...@gmail.com>:

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/fmLr_YIN3FYJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


--
Itzik Saban


Oskar Berggren

unread,
Feb 15, 2012, 8:55:02 AM2/15/12
to nhu...@googlegroups.com
I don't see the point of users subquery in that - there is no
correlation to the outer query so it will return the same value for
every row.

So it seems do boil down to something like (HQL):
select p.firstname, p.name, count(p) from Person p group by p.firstname, p.name

/Oskar


2012/2/15 Itzik Saban <itzik...@gmail.com>:

Nikhil Ketkar

unread,
Feb 15, 2012, 11:53:15 PM2/15/12
to nhusers
Hi Oscar,

The posted query is the simple one, the motto behind posting such
example is to ask whether such kind of query can be generated in
nhibernate of not using criteria api.

In practical scenario the inner query is more complicated and it will
contains dynamic part instead of (select id from users where userid =
12345') as id this query and now whatever is selected I should be
able to apply aggregation on these selected values that is what I am
trying to achieve.

Please let me know if you can point of something.

On Feb 15, 6:55 pm, Oskar Berggren <oskar.bergg...@gmail.com> wrote:
> I don't see the point of users subquery in that - there is no
> correlation to the outer query so it will return the same value for
> every row.
>
> So it seems do boil down to something like (HQL):
> select p.firstname, p.name, count(p) from Person p group by p.firstname, p.name
>
> /Oskar
>
> 2012/2/15 Itzik Saban <itziksa...@gmail.com>:
>
>
>
>
>
>
>
> > Subqueries in HQL.
>
> > בתאריך 15 בפברואר 2012 08:20, מאת Nikhil Ketkar <nmket...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages