掲示板

How to get distinct row in Dynamic Query

13年前 に Karthik Charles によって更新されました。

How to get distinct row in Dynamic Query

New Member 投稿: 7 参加年月日: 10/11/20 最新の投稿
Hi guys,

I need to get distinct row from table using DynamicQuery. Is it possible to get a distinct row?
For eg..

id title pid sid uid
----- --------- -------- ------- -------
1 Q1 1 1 1
1 Q1 1 1 1
1 Q1 1 1 1
1 Q2 1 1 1
1 Q2 1 1 1
1 Q3 1 1 1
----------------------------------------

I want to get the results as

id title pid sid uid
----------------------------------------
1 Q1 1 1 1
1 Q2 1 1 1

Pl help guys...
thumbnail
13年前 に jelmer kuperus によって更新されました。

RE: How to get distinct row in Dynamic Query

Liferay Legend 投稿: 1191 参加年月日: 10/03/10 最新の投稿
thats kind of a generic question. please post the query you are executing now
13年前 に Karthik Charles によって更新されました。

RE: How to get distinct row in Dynamic Query

New Member 投稿: 7 参加年月日: 10/11/20 最新の投稿
Hi Jelmer Kuperus,

Thanks for ur response...

 DynamicQuery query = DynamicQueryFactoryUtil.forClass(SetQuestionEntry.class);
          return SetQuestionEntryLocalServiceUtil.dynamicQuery(query);
   

I know the above query is to get all records from the table. But I need to give the condition to group by "title". Which criterion will use for it to get distinct titles?
Please suggest me..
thumbnail
13年前 に jelmer kuperus によって更新されました。

RE: How to get distinct row in Dynamic Query

Liferay Legend 投稿: 1191 参加年月日: 10/03/10 最新の投稿
I really can't help you unless you clearly describe what it is you want to do
13年前 に Karthik Charles によって更新されました。

RE: How to get distinct row in Dynamic Query

New Member 投稿: 7 参加年月日: 10/11/20 最新の投稿
Sorry for my english Jelmer,


          public static List<object> getAll(long userid) throws PortalException, SystemException {
               DynamicQuery query = DynamicQueryFactoryUtil.forClass(SetQuestionEntry.class);
               return SetQuestionEntryLocalServiceUtil.dynamicQuery(query);
         }
   <br><br>    I am new to liferay Jelmer, I used the above query to get all rows from the table. <br><br>    I will explain you clearly,<br><br>       I had a table with column name as 'title'.  I created number of rows under same title names. Please look over my first post under this topic for your reference. It contains two titles namely q1 and q2 totally six rows. I want to execute the query to get the distinct result, I want to get only two rows from it.<br><br>   I don't know how to do further from here. I hope you will understand what I required. Please provide sample codes that will be helpful.<br><br>   Thanks in advance.</object>
13年前 に Karthik Charles によって更新されました。

RE: How to get distinct row in Dynamic Query

New Member 投稿: 7 参加年月日: 10/11/20 最新の投稿
Hi Guys,

I need a solution for this. Pls help any one.
thumbnail
13年前 に Raja Nagendra Kumar によって更新されました。

RE: How to get distinct row in Dynamic Query

Expert 投稿: 484 参加年月日: 06/03/02 最新の投稿
You must add Criterion. Look at RestrictionsFactoryUtil to know the one for unique one you are looking for.

These URL's can be of more help.

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Queries+2:+DynamicQuery+API
http://www.liferay.com/web/minhchau.dang/blog/-/blogs/using-the-dynamic-query-api

Regards,
Raja Nagendra Kumar,
C.T.O
www.tejasoft.com
12年前 に Mykola M によって更新されました。

RE: How to get distinct row in Dynamic Query

New Member 投稿: 4 参加年月日: 11/01/20 最新の投稿
According to this - http://liferay-blogging.blogspot.com/2010/11/dynamicquery-api-in-liferay.html - if you do DynamicQuery you can use userQuery.setProjection(ProjectionFactoryUtil
.distinct(ProjectionFactoryUtil.property("yourPropertyNameHere")));