select max(id) of each* record

Asked

Viewed 1,079 times

-2

elect

opa personal, I have a query with this data of the image, I wanted to give a select only in max(id) of each numberExterno to save in another table@

  • 1

    "wanted to select only max(id) of each numberExtern" this does not make sense "of each numberExtern", if it is max will be of all, otherwise it would not be a max. as to insert in another table only do Insert with select or select into

  • I’ll rephrase my question.

1 answer

0

To get max(id) for each numberExtern, select with group by

Example:

select
    max(ID),
    NUMEROEXTERNO
from
    BA_COBAN.DETALHELOJAARQCADASTRAL
where
    NUMEROEXTERNOMATRIZ = '50494'  

Now use this select to do the select you already have to do the Insert in the table, so it will filter only the max of each external number.

Example:

select
    *
from
    (select
         max(ID),
         NUMEROEXTERNO
     from
         BA_COBAN.DETALHELOJAARQCADASTRAL
     where
         NUMEROEXTERNOMATRIZ = '50494') X
inner join BA_COBAN.DETALHELOJAARQCADASTRAL DE on DE.ID = X.ID  
  • @Diego Garcia If the answer was useful to you, if you can mark it as accepted , so when other users view your question they will see that you already have a correct answer and accept it for you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.