Combine Multiple Rows into One Cell Using SQL

Sdílet
Vložit
  • čas přidán 11. 09. 2024
  • Learn to take values from multiple rows and combine them into one cell using the power of SQL. I'll demonstrate a very elegant function you can use to accommodate this use case. We'll work through several examples on a simple data set. As a data analyst you need this tip in your bag of tricks!
    ★☆★ FOLLOW ME BELOW: ★☆★
    Blog ► anthonysmoak.com/
    Twitter ► / anthonysmoak
    Facebook ► / anthonybsmoak
    Instagram ► / @anthonysmoakdata
    Tableau Public ► bit.ly/3JMKsLY
    #SQL #data #analytics #data #dataanalyst #education #onlinelearning
    0:00: Intro
    0:33 Explore data set in Excel
    2:54 Explore data set in SQL Server
    4:06 The function you came to learn
    6:02 Combined data in alphabetical order
    7:26 Microsoft documentation
    8:02 Remove duplicates from results
    9:40 Join results to initial data using a CTE
    13:25 Outro (Remember to Super Thanks!)

Komentáře • 18

  • @SP-fc9bx
    @SP-fc9bx Před 5 měsíci +1

    You rock. SQL is so fun. I'm always learning something new. Thank you and thank everyone for sharing.

  • @LovelyJordy
    @LovelyJordy Před rokem +1

    Thank you Anthony. I’m learning SQL, Tableau, and Python right now and your videos are so helpful!❤

    • @AnthonySmoak
      @AnthonySmoak  Před rokem

      Thank you for sharing this comment Jordan!

  • @balogunvincent201
    @balogunvincent201 Před 5 měsíci +1

    This was really a great help for me

  • @uc7602
    @uc7602 Před rokem

    Great video. One suggestion... please consider either lowering or omitting the background music because I found it a bit distracting. Thank you, Anthony.

  • @hasanmougharbel8030
    @hasanmougharbel8030 Před rokem +1

    hello there, god bless your efforts..I have a simple enquiry as new sql learner.
    How are CTEs different from temporary tables?
    Thanks for taking care of this.

    • @AnthonySmoak
      @AnthonySmoak  Před rokem +2

      Great question. There are many differences but the biggest difference is that the CTE has to be used in the current query scope (re-execute the CTE code everytime you want to include those results). The temp table will exist for the entire duration of your session and does not need to be re-executed everytime you want to reference its results.

  • @lawrancegana6639
    @lawrancegana6639 Před rokem

    Is it work for oracle sql as well?

    • @AnthonySmoak
      @AnthonySmoak  Před rokem

      I believe Oracle has a string aggregate function. You may have to tweak the code a bit. Give it a try and let us know.

  • @aafreensultana1835
    @aafreensultana1835 Před rokem

    Will this work if i have it in views and there are alot of inner joins ?

  • @MrSparkefrostie
    @MrSparkefrostie Před rokem

    Do you perhaps know how to reverse this, i have a row with all the emails linked to the project in one cell separated by a ; i need to have all those emails listed each in a row and the project they dealt with

    • @AnthonySmoak
      @AnthonySmoak  Před rokem

      Try to experiment with the PARSENAME function in TSQL. The limitation may be that you need to know the project with the max number of emails, so you can repeat the PARSENAME function that many times. www.mssqltips.com/sqlservertip/6321/split-delimited-string-into-columns-in-sql-server-with-parsename/

    • @MrSparkefrostie
      @MrSparkefrostie Před rokem

      @@AnthonySmoak thank you, I managed to find string_split

    • @AnthonySmoak
      @AnthonySmoak  Před rokem

      Ok great. I was thinking you needed each value as a new column instead of a row. String Split should work. 👍🏽