6
How can I bring all records from a column that are not repeated. For example:
| tela | url | perfil | dataCriacao |
---------------------------------------------
| dica | /dica/ | ROLE_CDL | 2019-07-05 09:00:00 |
| dica | /dica/ | ROLE_MARKETING | 2019-07-05 09:00:00 |
| monitor | /monitor/ | ROLE_CDL | 2019-07-05 09:00:00 |
In this table as I could do a SELECT * FROM that would eliminate duplicate records from the column tela
and to return to me:
| tela | url | perfil | dataCriacao |
--------------------------------------------------------------
| dica | /dica/ | ROLE_CDL | 2019-07-05 09:00:00 |
| monitor | /monitor/ | ROLE_CDL | 2019-07-05 09:00:00 |
I have tried to perform a select distinct, but I was unsuccessful.
select DISTINCT tela from sua_tabela
didn’t work?– Tmilitino
Tried the function ROW_NUMBER ?
with CTE_RN as
(
 select 
 tela,
 url,
 perfil,
 dataCriacao,
 ROW_NUMBER() OVER(PARTITION BY tela ORDER BY tela DESC) as RN -- Função ROW_NUMBER CRIA UMA NUMERAÇÃO PARA CADA REC QUE SE REPETE 
 from Table_1
)

select * from CTE_RN 
where RN = 1
– Edvaldo Lucena
@Tmilitino it would work if I only wanted the screens so I could give
select distinct tela from nomedatabela
, but I need to get the whole registry. and not just the screen field.– Brendon Iwata
if it works, then you can do
select DISTINCT tela, url, perfil, dataCriacao from sua_tabela
ai returns the rest of the fields– Tmilitino
I can’t do that, because this is a JPA query, so I needed to return all the data right, for Binding to occur correctly and it already store as object, if I put field by JPA field returns me an array and then ends up breaking me. I guess I’ll have to remove the duplicates on the server.
– Brendon Iwata
understood now your scolding. it is good you put this in the question, because it is understood that it is a doubt only of sql and such, but it has much more involved.
– Tmilitino
The problem has been solved?
– João Paulo Araujo