Fórum

Need distinct values from the database

thumbnail
Madhura Shetty, modificado 9 Anos atrás.

Need distinct values from the database

Junior Member Postagens: 80 Data de Entrada: 07/11/13 Postagens Recentes
Hi,

Below is the code to get the data (list of product group) from the data base . I am able to get all the data from the database but i need the distinct values. I dont need repetitions and space , so please let me know how to do it please.


<aui:select name="PROGRP" id="PROGRP" label="<span style='font: red; font-weight:bold;
font-size: 14px;
font-family: Tahoma, Geneva, sans-serif;
text-align: right; '>Product Group:</span>">

<%
List<FAQTC> list = FAQTCLocalServiceUtil.getFAQTCs(-1, -1);
for (FAQTC lb: list) {
%>

<aui:option value="<%= lb.getProductGroup() %>">
<%= lb.getProductGroup() %>
</aui:option>

<%
}
%>
</aui:select>





Thanks & Regards
Madhura BS
thumbnail
David H Nebinger, modificado 9 Anos atrás.

RE: Need distinct values from the database

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Hmm, sounds like your table definition is simply wrong. A row should have a primary key and, by definition, the primary key is unique and therefore distinct.
thumbnail
Suresh Nimmakayala, modificado 9 Anos atrás.

RE: Need distinct values from the database

Liferay Master Postagens: 690 Data de Entrada: 18/08/04 Postagens Recentes
still you can't do much about your database now still want to remove from code

just a snapshot add to array list, set as HashSet and back to array give it a try


List<yourobject> objlist= new ArrayList<yourobject>();


for(yourobject yo : objlist){
objlist.add(oblect)
}
....................................



Set<yourobject> objsortlist= new HashSet<yourobject>(objlist);
objlist.clear();
objlist= new ArrayList<yourobject>(objsortlist);
return objlist;
thumbnail
David H Nebinger, modificado 9 Anos atrás.

RE: Need distinct values from the database

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
Suresh Nimmakayala:
just a snapshot add to array list, set as HashSet and back to array give it a try


Sorry, not sure what that really does to address the distinct values. Because the hash value from a record includes the different unique primary keys, there should be little if any hash value collisions. Pushing to a hash set effectively does nothing, so all of this extra work is just extra work with no benefit.

And besides, you still have to read every record of the database into memory (consider a case where you have 1 million rows) just to do all of this, then multiply by a few hundred or thousand concurrent users reviewing the same thing. Think this is still viable?