I have a requirement where I need to restrict number of records returned from a table for a particular flag and all records for the other flag value.
For example: contact-history
table has an element called IorM_flg
with possible values 'm' and 'o'.
I need to return only 10 records of 'o' and all records of 'm'.
I was about to write a query with union for this. Something like this:
select ch from contact_history where ch.rownum <= 10 and ch.IorM_flg = 'o'
Union All
select ch from contact_history where ch.IorM_flg != 'o'
Is this possible? Note that its a JPA query. (contact_history is object name)
Any other better suggestions welcome!