Fórumok

How to get distinct row in Dynamic Query

Karthik Charles, módosítva 13 év-val korábban

How to get distinct row in Dynamic Query

New Member Bejegyzések: 7 Csatlakozás dátuma: 2010.11.20. Legújabb bejegyzések
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
mohammed azam, módosítva 13 év-val korábban

RE: How to get distinct row in Dynamic Query

Regular Member Bejegyzések: 159 Csatlakozás dátuma: 2009.11.06. Legújabb bejegyzések
Hi karthik,

I have tried this piece of code it worked for me. Hope this works for you as well. I have tried in jsp file.

<%@page import="com.liferay.portal.kernel.dao.orm.ProjectionFactoryUtil"%> 
<%@ page import="com.liferay.portal.kernel.dao.orm.DynamicQuery" %>
<%@ page import="com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil" %>

<%
	List results1 = new ArrayList();
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(AzamTest.class);
	
	dynamicQuery.setProjection(ProjectionFactoryUtil.distinct(ProjectionFactoryUtil.rowCount()));
	
	results1.addAll(AzamTestLocalServiceUtil.dynamicQuery(dynamicQuery));

%>

<%=results1.size() %>
Karthik Charles, módosítva 13 év-val korábban

RE: How to get distinct row in Dynamic Query

New Member Bejegyzések: 7 Csatlakozás dátuma: 2010.11.20. Legújabb bejegyzések
Hi Azam,

Thanks for ur response..

The above query you mentioned returns the row-count of distinct values. But I need the whole rows which are distinct. Give me a suggestion please..
thumbnail
Leonid Zverugo, módosítva 10 év-val korábban

RE: How to get distinct row in Dynamic Query

New Member Bejegyzés: 1 Csatlakozás dátuma: 2014.01.11. Legújabb bejegyzések
Very old topic, but I found it only now, however, I hope this would be useful for somebody. Well, I had the same issue in my project (I am very new to Liferay emoticon ) - to select distinct column value using DynamicQuery:

    DynamicQuery query = DynamicQueryFactoryUtil.forClass(RequestForProposal.class)
                 .setProjection(
                     ProjectionFactoryUtil.distinct(
                         ProjectionFactoryUtil.property(StringConstant.PRIORITY_FIELD.toString())
                     )
                 );



Hope, this helps someone emoticon