Sql select most repeated value

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 96

  • @karthik1090
    @karthik1090 3 ปีที่แล้ว

    I haven't used SQL in a while as my current job didn't require it, your videos keeps me in touch with SQL and stops me from forgetting it. Thanks

  • @shuvo9131
    @shuvo9131 3 ปีที่แล้ว +25

    please continue the sql series of performance tuning.

  • @gagandeepsingh6126
    @gagandeepsingh6126 3 ปีที่แล้ว +22

    Sir please make complete series on SQL server performance tuning.

  • @freedomring3022
    @freedomring3022 3 ปีที่แล้ว

    very straight forward and to the point .. one issue, not major but should be accounted for, is if two names appear as the, say Tom appears 2 times and Sarah appears 2 times you would want both returned since they are both the most. The Top 1 clause won't work for you.

  • @ashutoshsingh5568
    @ashutoshsingh5568 3 ปีที่แล้ว

    God bless you sir. I am your very old student. I have learned .net by watching your lectures after I did my MCA.
    Thanks for your teachings.

  • @manjariganapathy3574
    @manjariganapathy3574 3 ปีที่แล้ว +8

    Waiting for your 5th video in sql performance tuning series

  • @srikanthsiri3569
    @srikanthsiri3569 3 ปีที่แล้ว

    Good explanation!. Just want to add my understanding if anyone is new to learning SQL..
    At 05:40 timestamp....
    Syntax of GROUP BY clause as follows:
    SELECT Column name
    FROM Table name
    [WHERE condition]
    GROUP Column name
    [HAVING Condition]
    [ORDER BY column name ASC/DESC]
    1. We will use HAVING if it contains aggregate functions: Per syntax (above), HAVING condition is used only after GROUP BY. which means aggregate functions (Count, Avg, Min, Max, Sum) works post grouping of the column.
    2. We will use WHERE if it DOES NOT contain aggregate functions: Per Syntax, WHERE is used only before GROUP BY, which means we are not using any calculation part here.
    3. Grouping is not mandatory for WHERE condition where as it is mandatory for HAVING.
    4. In SQL [..] brackets are used if a condition is optional*.
    Open for suggestions/comments/Dislikes/Likes :). Thank you for your time and have a good day, Happy Learning!

  • @poomanivenugopal3193
    @poomanivenugopal3193 2 ปีที่แล้ว

    The best explanation i never ever heard.. superb and Thank you so much

  • @jkdarshni882
    @jkdarshni882 3 ปีที่แล้ว +2

    Waiting for SQL server performance tuning videos...Very much helpful for us.

  • @rustedrootbeer
    @rustedrootbeer 3 ปีที่แล้ว +4

    There's a fallicy in your query. You need to actually do a RANK() OVER PARTITION BY NAME ORDER BY COUNT DESCENDING in a sub query and join that back to your parent table where the rank = 1. This will give you the first place name, and also account for when there might be >1 name repeated the same amount of times.

    • @mohamedabdelkader8003
      @mohamedabdelkader8003 ปีที่แล้ว

      good job pro , but i thinks it will be very difficult to catch it think this way it easy

  • @55shabeebmaulavi45
    @55shabeebmaulavi45 3 ปีที่แล้ว

    this was the exact video which I want , thanks a lot for your wonderful explanation sir

  • @ArtisticKalam
    @ArtisticKalam 3 ปีที่แล้ว +1

    Venkat sir you are my all time favourite.
    Requesting you to please please create a series for query optimisation and performance tuining
    We would be thankful to you.

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +4

      We already have a series on SQL Server Performance Tuning and Query Optimization. Hope you will find it useful.
      th-cam.com/play/PL6n9fhu94yhXg5A0Fl3CQAo1PbOcRPjd0.html

    • @ArtisticKalam
      @ArtisticKalam 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot thank you for your response.you are my guru and I am
      Highly obliged to see your response.
      Sir requesting you to please complete this with your ocean of knowledge like you did for General sql or if you already teach optimisation & performance tuining thing in paid form in online platform under some course I am ready to buy that

  • @salarkazazi7584
    @salarkazazi7584 3 ปีที่แล้ว +3

    Thank you so much, what if there were equal repeated values? like 2 Toms and 2 Sarahs and we wanna show them both?

    • @programit7155
      @programit7155 3 ปีที่แล้ว

      Instead of 'TOP 1' use 'TOP 2'

    • @salarkazazi7584
      @salarkazazi7584 3 ปีที่แล้ว

      @@programit7155 What if we dont know how many there are?Dynamic way of responding i meant

    • @programit7155
      @programit7155 3 ปีที่แล้ว

      @@salarkazazi7584 when we dont use TOP keyword we get all COUNT's then only we would know like what we could do with it. As shown in this video after using TOP 1 we get a single value. don't forget order by though.

    • @salarkazazi7584
      @salarkazazi7584 3 ปีที่แล้ว

      @@programit7155 Thank you

    • @GiovanniGaldamezH
      @GiovanniGaldamezH 3 ปีที่แล้ว +2

      Try this:
      SELECT Name
      FROM Students
      GROUP BY Name
      HAVING COUNT(Name)=(SELECT TOP 1 COUNT(Name) FROM Students GROUP BY Name ORDER BY COUNT(Name) DESC)
      ORDER BY Name

  • @rakeshpatil6263
    @rakeshpatil6263 3 ปีที่แล้ว +1

    Hi Sir,
    At video running time 3:55 if Mike/Sara has the count 2, then the query won't help to find the most repeated value.
    I mean if there is a tie between the most repeated value
    I found the following query helpful
    SELECT Name
    FROM Students
    GROUP BY Name
    HAVING COUNT(Name) = (
    SELECT MAX(TotalRepetitions)
    FROM (
    SELECT COUNT(NAME) AS TotalRepetitions,Name
    FROM Students
    GROUP BY Name
    ) AS result
    )
    Please let us know if there is an optimized way to achieve it.

    • @santoshpradhan9822
      @santoshpradhan9822 ปีที่แล้ว

      Select Name
      from Students
      group by Name
      having count(*) =(
      Select top 1 count(name) from Students group by name order by count(name) desc
      )

  • @shreyaspatil24
    @shreyaspatil24 2 ปีที่แล้ว

    thank you.. alternative answer for n times
    with result as (
    select name , count(*) as newtable from students group by name order by count(*)
    )
    select * from result where result.newtable = 1;

  • @LuigiZambetti
    @LuigiZambetti 3 ปีที่แล้ว +1

    Why don't you make a playlist for Azure Data Factory (the new SSIS) Venkat?

  • @tajlala7367
    @tajlala7367 3 ปีที่แล้ว

    U r great and true master for sql

  • @abreezy1st
    @abreezy1st 3 ปีที่แล้ว +1

    Can’t we use “where count(name) = 2” as well?

    • @jaypandey007
      @jaypandey007 3 ปีที่แล้ว

      Aggregate functions such as count, min, max are handled by HAVING Clause and not by WHERE Clause.

  • @softwaregiant9908
    @softwaregiant9908 3 ปีที่แล้ว +1

    Your voice of teaching is awesome 😌

  • @karangupta7027
    @karangupta7027 3 ปีที่แล้ว

    Very helpful..kindly share same kind of videos. More difficult queries to solve which is helpful in Interviews.
    You can find questions on coding but you can't find difficult queries on the internet. So it will be helpful ✌️

  • @a000000j
    @a000000j 3 ปีที่แล้ว

    Nice video but being your old subscriber I am expecting some more advance topics like you did before e.g. how to sql index work
    Keep it bro good work.

  • @vivekgupta-qn9xs
    @vivekgupta-qn9xs 3 ปีที่แล้ว +1

    Hello sir, if the most repeated values for more than one name then this top 1 will return the very first row. But we have to return all name for most repeated values.

  • @santoshadhikari9933
    @santoshadhikari9933 2 ปีที่แล้ว

    can we use it for int/float data type?
    or
    date datatype

  • @khikmatonnaev5083
    @khikmatonnaev5083 2 ปีที่แล้ว

    Best online trainer 💪 👌

  • @yogeshjoshi8021
    @yogeshjoshi8021 ปีที่แล้ว

    Not able to execute the sql query..Getting below error Msg 137, Level 15, State 2, Line 2
    Must declare the scalar variable "@FirstNamesList".

  • @laxmanp3133
    @laxmanp3133 3 ปีที่แล้ว +1

    Hi sir ,please do video on performance tunning and query optimization

  • @konduruvenkatraju7876
    @konduruvenkatraju7876 3 ปีที่แล้ว

    Nice explained all the videos sir👍Great work

  • @anupnair7465
    @anupnair7465 3 ปีที่แล้ว

    If I have a data of day 1 to 100 and I want to find which number is missing in between which query to fire pls help

  • @anlithsimha9577
    @anlithsimha9577 3 ปีที่แล้ว

    How to get bottom N records from a table and don't want apply sorting. Pls guide me how to do

  • @boostupvibes572
    @boostupvibes572 3 ปีที่แล้ว

    Thanks a lot, really your videos are learnable ... please do more SQL PLSQL Interview questions

  • @sahilsachdeva1018
    @sahilsachdeva1018 3 ปีที่แล้ว +2

    When can we expect new videos on azure? Eagerly waiting 😊 for that

  • @snehabathula3550
    @snehabathula3550 3 ปีที่แล้ว

    Could you please help with finding records with null values

  • @aakashshanavas8437
    @aakashshanavas8437 2 ปีที่แล้ว

    This is so useful. Thank you
    .

  • @sibongilevilakazi1478
    @sibongilevilakazi1478 2 ปีที่แล้ว

    hello,how can you place a unique value between 2 high values

  • @codingwall
    @codingwall 3 ปีที่แล้ว

    Thank you. keep posting new videos.

  • @mccg4337
    @mccg4337 ปีที่แล้ว

    you are awesom sir, just what I was looking for ..haha

  • @jalaluddin1753
    @jalaluddin1753 3 ปีที่แล้ว

    Thank you soo much sir for uploading this video on my request

  • @nayanamtanuj
    @nayanamtanuj 3 ปีที่แล้ว

    Are these not being put in a playlist? There is one SQL playlist with 150 videos, is this video part of that series?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +2

      Hi Tanuj - It's part of SQL Server Interview Questions and Answers playlist at the following link.
      th-cam.com/play/PL6n9fhu94yhXcztdLO7i6mdyaegC8CJwR.html

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      SQL Server Tutorial for Beginners (All the basic and advanced concepts)
      th-cam.com/play/PL08903FB7ACA1C2FB.html
      SQL Server Performance Tuning and Query Optimization
      th-cam.com/play/PL6n9fhu94yhXg5A0Fl3CQAo1PbOcRPjd0.html

    • @nayanamtanuj
      @nayanamtanuj 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot THANK YOU SO MUCH! 🙏🏻

  • @flaviusioan69
    @flaviusioan69 3 ปีที่แล้ว

    Very clear explanation...tnx

  • @ramilaliyev6669
    @ramilaliyev6669 3 ปีที่แล้ว

    Hi. If two different records have same count, what will be result ?

    • @chezchezchezchez
      @chezchezchezchez 3 ปีที่แล้ว

      Why don’t you run it and find out

    • @simon-white
      @simon-white 3 ปีที่แล้ว

      This is a good question, and I'd generally echo Jim's response - you learn best when you try for yourself, especially if something unexpected happens. However, if you try it, the answer alone would give you an incomplete picture, so I'd recommend also investigating the 'WITH TIES' clause.

    • @cyb3r1
      @cyb3r1 3 ปีที่แล้ว +1

      It will be a random result with the top count unless you have specified additional order by values. If you want to receive all of the results with the top count you can run something like this:
      select Name
      from Students
      group by Name
      having count(Name) =
      (
      select top 1 count(Name)
      from Students
      group by Name
      order by count(Name) desc
      )

    • @ramilaliyev6669
      @ramilaliyev6669 3 ปีที่แล้ว

      @@chezchezchezchez I did it, before)

    • @simon-white
      @simon-white 3 ปีที่แล้ว +2

      @@cyb3r1 This was the reason for my hint. If you want all names with the top count, you can achieve the same result but simpler like this:
      SELECT TOP 1 WITH TIES Name
      FROM Students
      GROUP BY Name
      ORDER BY COUNT(Name) DESC
      "WITH TIES" allows any matching results at the end of the result set to overflow the usual TOP number limit.

  • @gouthammano2992
    @gouthammano2992 3 ปีที่แล้ว

    Hello venkat if possible could u please make a tutorial video about sql locks, it would be much appreciated

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      Hello Goutham - Locks are discussed in SQL Server Tutorial for beginners course. Please check out videos from Part 78 to 86. Hope you will find them useful.
      www.pragimtech.com/courses/sql-server-tutorial-for-beginners/

  • @allinonepkg
    @allinonepkg 3 ปีที่แล้ว

    Sir txs.your video is helpful. Please make videos on how to change text to editable onclick in the text

  • @BitcoinBabu369
    @BitcoinBabu369 3 ปีที่แล้ว

    thanks Venkat. 👍

  • @Gauravkumar-jm4ve
    @Gauravkumar-jm4ve 3 ปีที่แล้ว

    Tx u so much ❤️🙏 please keep doing more

  • @devendrasingh815
    @devendrasingh815 3 ปีที่แล้ว +1

    Nice sir
    Please sir
    make videos on SQL performance & tuning

  • @morsheddld
    @morsheddld 3 ปีที่แล้ว

    Great tutorial.

  • @hairavyadav6579
    @hairavyadav6579 3 หลายเดือนก่อน

    with cte as (select *, count(name) over(partition by name) rnk from nam)
    select distinct(name) from cte where rnk=n;

  • @ashajyothi06
    @ashajyothi06 3 ปีที่แล้ว

    Thank you venkat sir🙂

  • @manishanaik1443
    @manishanaik1443 ปีที่แล้ว

    Thank you so much video was helpfull😊

  • @wiepcorbier
    @wiepcorbier 3 ปีที่แล้ว

    Nice, thanks 👊

  • @mhashir90
    @mhashir90 3 ปีที่แล้ว

    Sir are you going to cover MongoDB anytime soon?

  • @sanjaypardeshi8914
    @sanjaypardeshi8914 3 ปีที่แล้ว +2

    👌

  • @hairavyadav6579
    @hairavyadav6579 3 หลายเดือนก่อน

    with cte as(select *,row_number() over(partition by name) as rnk from nam)
    select name from cte where rnk = (select max(rnk) from cte);

  • @Melodychoice601
    @Melodychoice601 3 ปีที่แล้ว

    Please make video on ....counting no. Of letters getting repeated in any word.....like crocodile have c letter 2 times

  • @vipinsingh-ji8dj
    @vipinsingh-ji8dj 3 ปีที่แล้ว

    Please continue with this series

  • @RadhaKrishnanjG
    @RadhaKrishnanjG 3 ปีที่แล้ว

    please start for SQL JSON and SQL query optimization

  • @ManiKantamasteringtheknowledge
    @ManiKantamasteringtheknowledge 3 ปีที่แล้ว

    Productive 📚

  • @FunnyComedian3875
    @FunnyComedian3875 3 ปีที่แล้ว

    Please try to give the real time scenarios also. Real world scenarios along with examples. It's request

  • @sravankumar1767
    @sravankumar1767 3 ปีที่แล้ว

    Nice explanation 👌

  • @boostupvibes572
    @boostupvibes572 3 ปีที่แล้ว

    Your voice make me feel cool

  • @ajoealex9976
    @ajoealex9976 3 ปีที่แล้ว

    Can you pls add a tutorial for WPF

  • @ubaid25
    @ubaid25 3 ปีที่แล้ว

    Thank you so much

  • @sleeepymoe
    @sleeepymoe 3 ปีที่แล้ว

    Please make a series about Apache Cassandra

  • @wahibaa3150
    @wahibaa3150 3 ปีที่แล้ว

    Thank you

  • @appleaday3635
    @appleaday3635 2 ปีที่แล้ว

    just a heads up this wont work in mysql

  • @muhammadawais-vb7mz
    @muhammadawais-vb7mz 2 ปีที่แล้ว

    thank you sir

  • @UnstoppableGaurang
    @UnstoppableGaurang 3 ปีที่แล้ว

    Please make more video likw this...

  • @mohamedabdelkader8003
    @mohamedabdelkader8003 ปีที่แล้ว

    thanks bro

  • @raqibul1000
    @raqibul1000 3 ปีที่แล้ว

    Plz continue sql performance series

  • @SrDlay
    @SrDlay 3 ปีที่แล้ว

    ty

  • @gkmishra2009
    @gkmishra2009 ปีที่แล้ว

    make video on Data Structure sir

  • @mageshkarm459
    @mageshkarm459 3 ปีที่แล้ว

    Select name from (Select name, count (name) as value from tablename
    Group by name)
    Where value = 2

  • @asimkumarchakraborty2456
    @asimkumarchakraborty2456 3 ปีที่แล้ว

    Sir start big query please

  • @anirudhsrivastava3530
    @anirudhsrivastava3530 2 ปีที่แล้ว

    if TOP 1 doesnt work , use LIMIT 1 at the end of query