Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DISTINCT in EJB-QL

 
Carlos Llona
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:

I have a doubt about the clause DISTINCT, I dont understand what exactly does!!!.

What criteria does distinct uses to determine what object is repited?

Example

SELECT DISTINCT OBJECT(p)
FROM Player p

in this example what does distinct serch to determinate if one object is repeated? it searches all the fields??? except primary keys or what?javascript: x()

I expect that all opf you understand the question, if no, please show an example of distinct and exactly what things it does.

thanks a lot

carlos
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a look at the EJB spec section 11.2.8 (SELECT clause), it states:

The DISTINCT keyword is used to specify that duplicate values must be eliminated from the query result.


In clear it means, that if the query you make against the DB ever returns duplicate values, only one of them will show up in the result set.
 
Carlos Llona
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Valentin! but

then, Distinc eliminates my entities repeated? if my query bring me for example the player with the primary key="00001" 5 times. with distinc I will only recive 1 record. is that right?

but!!!.

are there any different for example if I do this?:
SELECT DISTINCT OBJECT(p)
FROM Player p

or

SELECT OBJECT(p)
FROM Player p

In my database sample there are only 10 records. I suposse that the two queries always bring me 10 records. I dont imagine in what case (maybe using the clouse where) I could get a record repeated.

can you give me one sample plz

thanks a lot

Carlos
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic