How to Add a Row Number to Your SQL Query Using row_number and partition by

Поділитися
Вставка
  • Опубліковано 19 гру 2024

КОМЕНТАРІ •

  • @DCh-ks6ug
    @DCh-ks6ug 4 місяці тому +1

    is it necessary to use order by function in the row_number function ?

  • @jimmyahmadu
    @jimmyahmadu 2 місяці тому +1

    how do you update your table with the serial row number

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 місяці тому

      Well, the row number is calculated, so you can just update your table and then re-run the query to get the new row numbers. If you want the numbers to be static after you generate the query, perhaps insert the results into a temp table or something like that, then work on that table.

  • @sonathena3150
    @sonathena3150 2 роки тому +1

    Hello Sean, do you have a copy of the dataset in this discussion? I hope you do have so we can try it by ourselves. Thanks

  • @diegovaldes3785
    @diegovaldes3785 Рік тому +1

    is there a way that the row number continues the sequence after running the same query again?

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  Рік тому

      Great question. It should continue generating more numbers if you added rows to the table, then executed the query again. Is that what you mean?

    • @diegovaldes3785
      @diegovaldes3785 Рік тому

      @@seanmackenziedataengineering hmm let me give you an example: I made a query that selects data based on a search criteria and want a sequence number related to each one of the items of this data, then a process unrelated to SQL does things with that data so it does not fit with the search criteria. What I need is that, whenever new data comes in that fits the search data, the sequence number continues where it was left

  • @maheshs8069
    @maheshs8069 2 роки тому +1

    Sir, will these rownum work for table with million record

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 роки тому

      I don't see why not! Give it a try. It may slow down though. At a point, you may want to just add a column to that table and make it persistent (and faster to work with).

  • @USA_to_Asia_in_2024
    @USA_to_Asia_in_2024 5 місяців тому +1

    GREAT explanation.

  • @sarahgorton8927
    @sarahgorton8927 2 роки тому +1

    very well explained, thank u!

  • @Oleemil89
    @Oleemil89 6 місяців тому +1

    Nice video! I enjoyed the intro song, but people have different expectations i guess. Who is playing and what song is it? Had a nice riff

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  6 місяців тому

      I believe that track was called "Ripped" and was included with license as part of the Camtasia studio selections.. 2019 or 2020 version iirc. I thought it was groovy!

  • @anilmanuka2052
    @anilmanuka2052 2 роки тому +1

    How to update empty column a value in declare table

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 роки тому

      If you are creating a new table, you can use a default to fill values that are not selected. If you wanted a date for example, you could make the field:
      MyDateField datetime default GetDate()

  • @alekkermd7775
    @alekkermd7775 2 роки тому +1

    The background music is very distracting.

    • @seanmackenziedataengineering
      @seanmackenziedataengineering  2 роки тому

      Thanks for the feedback! All my newest videos removed the intro music.

    • @USA_to_Asia_in_2024
      @USA_to_Asia_in_2024 5 місяців тому

      Check out the mirror and you'll see a crybaby who cries about music and should have bigger fish to fry