Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    10 page views
  •   0 video views
  • 2024, October 31, Thursday

#046 Limit the amount of records in Azure SQL

Como limitar a quantidade de registros em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server

This T-SQL code performs a query on the "f.MOEDA_COTACOES" table. I'll explain each

part of the code:SELECT [DATE], [
  1. CURRENCY], [VALUE], ROW_NUMBER() OVER (ORDER BY [DATE])

    • :select: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [DATE], [CURRENCY
    • ], [AMOUNT]: Select the "DATE", "CURRENCY" and "AMOUNT" columns.
    • ROW_NUMBER() OVER (ORDER BY [DATE]): Uses the ROW_NUMBER() function to assign a row number to each record, sorted by the "DATE" column.
  2. FROM [f].[ MOEDA_COTACOES]:

    • FROM: Indicates the table from which the data will be selected.
    • [f]. [MOEDA_COTACOES]: This is the name of the table from which the data will be extracted. The prefix "f." suggests that the table is in a schema called "f".
  3. ORDER BY [DATA]:ORDER BY

    • : Sorts the results of the query.
    • [DATE]: Sorts the results based on the "DATE" column, in ascending order, i.e. from the earliest to the most recent date.
  4. OFFSET 20
  5. ROWS FETCH NEXT 10

    ROWS ONLY:OFFSET 20
    • ROWS: Skips the first 20 records in the ordered set.
    • FETCH NEXT 10 ROWS ONLY: Returns the next 10 records after the skipped 20
.Therefore, the

code returns the data from the "DATE", "CURRENCY", and "AMOUNT" columns of the "f.MOEDA_COTACOES" table, with the addition of a row number assigned to each record, sorted by the "DATE" column. The query starts at the twenty-first record (due to OFFSET) and returns the next 10 records. This is useful when you want to paginate the results of a query into specific blocks.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 1 min 23 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now