Top 10 SQL interview Questions and Answers | Frequently asked SQL interview questions.

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

КОМЕНТАРІ • 323

  • @ankitbansal6
    @ankitbansal6  Рік тому +21

    Master the art of with my zero to hero SQL course. The course is focused on data analytics and covers all the advanced concepts starting from scratch.
    www.namastesql.com/course-detail/think-sql-go-from-zero-to-hero-english
    Course contains 2 portfolio projects and a bonus session on Tableau.
    100+ interview problems to crack any SQL INTERVIEW.

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

      Is it in udemy ?

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

      @@avinashmishra4995 nope

    • @Rohitraj-mv3pz
      @Rohitraj-mv3pz Рік тому

      ​@@ankitbansal6 bro i really need your help.. is there any way i can reach out to you..

    • @bhartisingh3750
      @bhartisingh3750 7 місяців тому

      Delete duplicate records query in not working in databricks notebook for deleting duplicate records from a table.. is there any way to do this in databricks notebook table?

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

      Bro you have taught everything for free in your channel only, why would I will but the course.

  • @mariecurie5245
    @mariecurie5245 2 роки тому +82

    create table emp(
    emp_id int,
    emp_name varchar(20),
    department_id int,
    salary int,
    manager_id int,
    emp_age int);
    insert into emp
    values
    (1, 'Ankit', 100,10000, 4, 39;
    insert into emp
    values (2, 'Mohit', 100, 15000, 5, 48);
    insert into emp
    values (3, 'Vikas', 100, 10000,4,37);
    insert into emp
    values (4, 'Rohit', 100, 5000, 2, 16);
    insert into emp
    values (5, 'Mudit', 200, 12000, 6,55);
    insert into emp
    values (6, 'Agam', 200, 12000,2, 14);
    insert into emp
    values (7, 'Sanjay', 200, 9000, 2,13);
    insert into emp
    values (8, 'Ashish', 200,5000,2,12);
    insert into emp
    values (9, 'Mukesh',300,6000,6,51);
    insert into emp
    values (10, 'Rakesh',300,7000,6,50);

    • @ankitbansal6
      @ankitbansal6  2 роки тому +7

      Thank you 😊

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

      thanks

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

      god bless you

    • @kartikpidurkar9590
      @kartikpidurkar9590 2 роки тому +10

      create table orders(
      customer_name char(10),
      order_date date,
      order_amount int,
      customer_gender char(6)
      );
      insert into orders values('Shilpa','2020-01-01',10000,'Male');
      insert into orders values('Rahul','2020-01-02',12000,'Female');
      insert into orders values('Shilpa','2020-01-02',12000,'Male');
      insert into orders values('Rohit','2020-01-03',15000,'Female');
      insert into orders values('Shilpa','2020-01-03',14000,'Male');

    • @kartikpidurkar9590
      @kartikpidurkar9590 2 роки тому +12

      create table department(
      dept_id int,
      dept_name varchar(10)
      );
      insert into department values(100,'Analytics');
      insert into department values(300,'IT');

  • @Ghost-of-uchihaaa
    @Ghost-of-uchihaaa 6 місяців тому +2

    This is my one-stop video before every interview for the past years.
    Brushes up my SQL skills like no other

  • @tupaiadhikari
    @tupaiadhikari 2 роки тому +27

    For the First time in 10 years, I am feeling confident with using SQL, only after watching your series of videos. Earlier I used Python to do data preprocessing after doing Vanilla Select * from Table Statement, which was not a recommended approach for memory efficiency.

    • @ankitbansal6
      @ankitbansal6  2 роки тому +5

      This is great. Best place to play with data is where it is residing 😊

  • @abhishek_grd
    @abhishek_grd 2 роки тому +3

    Bang on ! Started product based companies interview prepration for Sr. DE role ( Google/Microsoft/Ubder/Amazon/Expedia / AirBnB) etc...and your content is crisp and clear. Thanks

  • @yashsoni2113
    @yashsoni2113 2 роки тому +8

    DDL and Insert values for emp table.
    create table emp(
    emp_id int,
    emp_name varchar(20),
    department_id int,
    salary int,
    manager_id int,
    emp_age int);
    insert into emp
    values
    (1, 'Ankit', 100,10000, 4, 39),
    (2, 'Mohit', 100, 15000, 5, 48),
    (3, 'Vikas', 100, 10000,4,37),
    (4, 'Rohit', 100, 5000, 2, 16),
    (5, 'Mudit', 200, 12000, 6,55),
    (6, 'Agam', 200, 12000,2, 14),
    (7, 'Sanjay', 200, 9000, 2,13),
    (8, 'Ashish', 200,5000,2,12),
    (9, 'Mukesh',300,6000,6,51),
    (10, 'Rakesh',300,7000,6,50);

  • @sheikhshah2593
    @sheikhshah2593 Рік тому +3

    Literally great.
    In all my SQL interviews one or the other is asked.
    Subscribed

  • @aasthamehtatech
    @aasthamehtatech 2 роки тому +4

    Crisp & insightful

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

    I am watching your one video each morning.
    So one day I will work as data engineer in good product based company.

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

      Thats a great way of preparing yourself 😊🙏

  • @akp7-7
    @akp7-7 2 роки тому +1

    Wow it wsd asked today delete duplicates..thanks for the videos.it is really really helpful

  • @manishgnagpure
    @manishgnagpure 3 місяці тому

    Hi Ankit ji,
    I seen some of the videos and those are very interesting, and useful.
    I request you to create a video on SQL Index in details with examples.
    1. Before creating index how the data loding in page level. And after creating index what kind of table ( page level) structure will be.
    2. What will be structure while create only cluster and only noncluster and both.
    Mean every one can understand beginners to exp students.
    Waiting for your new video.

  • @rahulmishra1523
    @rahulmishra1523 3 дні тому

    Very nice 👍❤

  • @pavitrashailaja850
    @pavitrashailaja850 2 роки тому +3

    Thnks for the video. Very helpful 👍

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

    I solved it using self join: as we are performing row level aggregation, I guess this is a good case for that:
    SELECT DISTINCT(e1.emp_id),
    e2.val as salary,
    e3.val as bonus,
    e4.val as hike_percent

    FROM emp_compensation e1
    JOIN emp_compensation e2
    ON e1.emp_id = e2.emp_id AND e2.salary_component_type = 'salary'
    JOIN emp_compensation e3
    ON e1.emp_id = e3.emp_id AND e3.salary_component_type = 'bonus'
    JOIN emp_compensation e4
    ON e1.emp_id = e4.emp_id AND e4.salary_component_type = 'hike_percent';
    Approach 2:
    with stats as (
    SELECT emp_id,
    CASE WHEN salary_component_type = 'salary' THEN val END as salary,
    CASE WHEN salary_component_type = 'bonus' THEN val END as bonus,
    CASE WHEN salary_component_type = 'hike_percent' THEN val END as hike_percent
    FROM emp_compensation)
    SELECT emp_id,
    SUM(salary) as salary,
    SUM(bonus) as bonus,
    SUM(hike_percent) as hike_percent
    FROM stats
    GROUP BY emp_id

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

      Sorry I wanted to post in the section of this question: ua-cam.com/video/O6mDdUIvx9k/v-deo.html

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

      @Md Jahidul Islam Razan - Approach 1 - 2.44 seconds vs Approach 2 - 1.31 seconds , i have tested in databricks community edition ,since underlying database is usually mysql, postgressql i think, CTE is more quicker to output both approaches are good !

  • @suman3316
    @suman3316 2 роки тому +2

    Very Useful...I hope part2 will come soon

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

    You always rock sir I love watching your video's and commenting too 💯

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

    I was asked 3 questions out of 5 from your list. Thanks alot

  • @BeingSam7
    @BeingSam7 4 місяці тому

    I just discovered you, subscribed you and started watching your videos. I was asked a question in an interview which is similar to q 6 but a li'l twist in it.
    Q - get 2nd highest salary from each dept and if a dept does not have a second salary then first salary should appear in result.

    • @rohitas7586
      @rohitas7586 Місяць тому

      Hello - How to solve to bring the first highest record if second highest is not available. appreciate any suggestions.

    • @Truth___
      @Truth___ Місяць тому

      @@rohitas7586
      Query for getting 2nd highest if not present then 1st highest-
      with cte as (
      select * from (
      select *, dense_rank() over(partition by department_id order by salary desc) as rnk
      from emp
      ) a
      )
      select distinct emp.department_id,
      coalesce(cte.emp_id, first.emp_id),
      coalesce(cte.emp_name, first.emp_name),
      coalesce(cte.manager_id, first.manager_id),
      coalesce(cte.salary, first.salary) as salary
      from emp left join cte on emp.department_id = cte.department_id and cte.rnk=2
      left join cte as first on emp. department_id = first. department_id and first.rnk=1
      order by emp.department_id
      ;
      DDL for emp table and insert query-
      create table emp(
      emp_id int,
      emp_name varchar(255),
      department_id varchar(255),
      salary int,
      manager_id int);
      insert into emp values(2,'Mohit', '100', 15000, 5),
      (3, 'Vikas','100',10000,4),
      (1,'Ankit','100',10000,4),
      (4,'Rohit','100',5000,2),
      (5,'Mudit','200',12000,6),
      (6,'Agam','200',12000,2),
      (7,'Sanjay','200',9000,2),
      (8,'Ashish','200',5000,2),
      (1,'Saurabh','900',12000,2);

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

    Yes, you are absolutely right, Many questions are based on your teaching. Thanks again for this great help Ankit!!

  • @suketshah7697
    @suketshah7697 2 роки тому +3

    very simple way to explain...Nice!

  • @addhyasumitra90
    @addhyasumitra90 5 місяців тому +2

    create table department(

    dept_id int,
    dept_name varchar(10)
    );

    insert into department values(100,'Analytics');
    insert into department values(300,'IT');
    create table orders(
    customer_name char(10),
    order_date date,
    order_amount int,
    customer_gender char(6)
    );

    insert into orders values('Shilpa','2020-01-01',10000,'Male');
    insert into orders values('Rahul','2020-01-02',12000,'Female');
    insert into orders values('Shilpa','2020-01-02',12000,'Male');
    insert into orders values('Rohit','2020-01-03',15000,'Female');
    insert into orders values('Shilpa','2020-01-03',14000,'Male');

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

    Your videos are very good and helpful. Thank you for providing data with create and insert statements.

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

    Great video! Loved that last question. Subbed and eager to practice more SQL with your other videos

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

    keep doing more videos like it. It really helped me in my job interview today. I am able to answer the question of how to remove duplicates from a table because of your videos.

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

    Amazing video, tomorrow I have an interview, I was clueless how to start and where to start, now I know what to do for tomorrow :))
    Thanks for sharing :)

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

    I have subscribed and liked . you are doing wonderful job

  • @vsagar4b38
    @vsagar4b38 8 днів тому

    Thanks for the Video

  • @rohitsehajpal9295
    @rohitsehajpal9295 Рік тому +4

    Hi Ankit, first of all this is really a great initiative that you are sharing all this knowledge and explaining the complex queries in a very easy way.
    And because of this I am really glad to tell you that your channel has majorly helped me to crack one of the SQL interview. Thank you so much for such a great effort and we all wish to see some more complex queries and concepts in coming future, once again thank you so much. Wish you a great health!

    • @YG-jb2in
      @YG-jb2in Рік тому +1

      Hey for which position you cleared the interview. And you cleared it as a fresher or experienced. Please reply.

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

    Good explanation👏 Please do more intermediate and advanced level of concepts in SQL.

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

    You just earned a subscribe from me bro. I haven't used SQL in years, but due to a career change I'm planning to have soon, I'll need to learn more about SQL in-depth alongside bettering my skillset in C++ programming.

  • @gauravghosh8002
    @gauravghosh8002 3 місяці тому +1

    Sir by looking at this video it seems SQL is very easy but actually it's not so easy sir, in interview same questions I faced nervous and end up giving wrong query.

  • @AnandaKrishna-t3h
    @AnandaKrishna-t3h 6 місяців тому

    Ankit sir added humour silently in this video with q10 😃

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

    Thanks sir for this amazing video

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

    Really Master class videos Ankit, Thanks.

  • @KapilKumar-hk9xk
    @KapilKumar-hk9xk 7 місяців тому

    but CTE doesn't support delete operations right...I tried it but got below error
    "The target table cte of the DELETE is not updatable"
    with cte as
    (select *,
    row_number() over (partition by md5(concat_ws(",",emp_id,emp_name,emp_age))) as dup_row_id
    from employee)
    delete from cte where dup_row_id>1;

    • @ankitbansal6
      @ankitbansal6  7 місяців тому +1

      It works only in SQL server

    • @KapilKumar-hk9xk
      @KapilKumar-hk9xk 7 місяців тому

      @@ankitbansal6 ok. thanks for replying 😊

    • @garimabatra2658
      @garimabatra2658 7 місяців тому

      @@ankitbansal6 What should be the approach for MYSQL?. Thanks in advance

  • @gameply347
    @gameply347 9 місяців тому

    I guess we can use subquery table as a normal table to display information using alias and where clause , but when it comes to comparison it needs to return only 1 value :) !!

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

    revised today for deloiite interview and suscribed too

  • @hairavyadav6579
    @hairavyadav6579 4 місяці тому

    Hi Sir,
    Big thank to you i learn lot of things in sql after watching your video .
    I want to add to solution from my side please let me know this will fine or not?
    1) with cte as (
    select *,row_number() over(partition by emp_id order by time desc) as rnk from hospital)
    select count(*) from cte where rnk =1 and action ="in";
    2) select count(*) as total_person from hospital h where time =(Select max(time) from hospital h1 where h1.emp_id = h.emp_id) and action ="in";
    Waiting for your response.
    Again big thank to you.

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

    Superb video..liked every second of the video 💖

  • @abdulwahab-rw1yq
    @abdulwahab-rw1yq 2 роки тому

    Thanks Ankit its very helpful in interivews wish i had come across your videos early.. thnks much

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

    Wow such a nice content. Please zoom a bit while making videos. Because most audience watch it over phone it strain the eyes

  • @raghum4938
    @raghum4938 9 місяців тому

    simple and clear explanation!!

  • @k.hariharasudan9335
    @k.hariharasudan9335 9 місяців тому

    Q7. MSSQL does not depend on case-sensitive but in the Oracle is depend on the case-sensitive

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

    Thanks for this video.

  • @OmkarShinde-bz7oy
    @OmkarShinde-bz7oy Рік тому

    yeah it was really important vid as see for the interveiw sceneriao

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

    Just landed here bro you are doing amazing job

  • @ammarfasih3866
    @ammarfasih3866 3 місяці тому

    In the first question where we wanna find out the duplicates, we knew that the duplicates would be as per emp_id. How about if we wanna check if the entire row is unique or not rather than checking any particular column?

  • @surabhijagadish5210
    @surabhijagadish5210 10 місяців тому +1

    Awesome

  • @sasidharreddy5008
    @sasidharreddy5008 7 місяців тому

    you don't need the motivation from others because, you yourself is a motivation 🤗

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

    Very Good explanation!

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

    Thanks a lot, Learned lots of new concepts.

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

    Thanks ankit, ur videos always encourage and boost confidence to prac more n go beyond our limit. Thanks Man

  • @suryanshsinghkarchuli9892
    @suryanshsinghkarchuli9892 2 роки тому +2

    for better reach, keep creating content

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

    Hi Ankit, loved your all videos. Looking forward to see a video on subqueries,

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

    5/123
    Stuck with 2 ques , coz i'm using mysql

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

    thanks, it actually let me through so i could download it.

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

    You are doing really awesome. Please keep doing this.
    One suggestion: Please don't forget to add create table script.

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

      Thank you. Scripts are there in most of the video description box. Might have missed few in my initial videos. Will put them soon.

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

      @@ankitbansal6 Cool

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

    Great content. Thank you Ankit

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

    @Ankit Bansal bhai if we have left whats the use of right join ?

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

    Thank for the video 🙏

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

    Just loving your content.. Very well explained.

  • @SubhamDas-tb3xf
    @SubhamDas-tb3xf 6 місяців тому

    Hey Ankit! I was thinking about that delete duplicate question. U r deleting the duplicate data from cte which is a temporary result set , right? It is working fine but how it's deleting from original table?
    MySQL doesn't support this from 8+ versions I guess..we have to use that cte query like a subquery in mysql.
    But in ssis it is working. Even in leetcode !
    But I think it is always better to reference the original table rather than querying from cte i.e a temporary result set. Selection is fine with cte but dml operation!
    Let me know about your thoughts, I would love to hear!

  • @agirmaus-lh9zi
    @agirmaus-lh9zi Рік тому

    very helpful ..thanks

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

    thanks Ankit..good tutorial..

  • @NitishKumar-xr9tx
    @NitishKumar-xr9tx 9 місяців тому

    In 2nd Question of removing duplicates: We are deleting values from the CTE table which is a TEMP table. Then how it is deleting values from the MAIN table?

  • @AnshuKumar-lh4gr
    @AnshuKumar-lh4gr 2 роки тому +1

    Good one .. !!

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

    with CTE as
    (
    select * ,row_number() over(partition by emp_id order by emp_id) as rnk from emp order by emp_id asc
    )
    delete from CTE where rnk > 1
    From CTE we can't delete records?

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

    Thank you so much.
    Make vidoes on JOINS.

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

    You just earned a subscriber really great content🥺

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

    It will be helpful if you can create videos on views and stored procedures

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

    Tqsm for awesome explanation 🔥

  • @Ian15278
    @Ian15278 3 місяці тому +1

    with dup as (
    select
    ROW_NUMBER() over(partition by emp_id order by emp_id desc) as Find_duplicate
    from emp)
    delete from emp
    where emp_id in (
    select *
    from dup
    where Find_duplicate > 1);

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

    Very helpful sir, thank you!

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

    Very well explained... 👌

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

    Great video, I took down some notes!

  • @shakthimaan007
    @shakthimaan007 4 місяці тому

    Questions:
    Q1 - How to find duplicates in a given table
    Q2 -> How to delete duplicates
    Q3 -> difference berween union ana union all
    Q4 -> diffrence between rank.row number and dense rank
    Q5 -> employees who are not present in deparament table
    Q6 > second highest salary in each dep
    Q7 -> find all transaction done by Shilpa
    Q8 -> self join, manager salary > emp salary
    Q9 -> Joins Left join/äner join
    Q10 -› update query to swap gender

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

    5th question can we also done used left anti right?
    like where dep.deptid is null?

  • @harini2933
    @harini2933 Рік тому +2

    Hey Ankit,
    I'm running below query for deleting duplicates -Q2 :
    WITH cte as (SELECT * , row_number() OVER( PARTITION BY emp_id ORDER BY emp_id ) AS rn FROM emp)
    DELETE FROM cte WHERE rn>1
    but, I'm getting error : "Error Code: 1288. The target table cte of the DELETE is not updatable" .
    Kindly reply. TIA 😇

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

      Try delete * . Which rdbms are you using?

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

      hi , did you got the solution for the above query
      coz i am facing the same issue

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

      @@yatinshekhar787 no I couldn't

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

      before delete alias a will be give

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

      with cte as ( select * ,row_number() over(partition by emp_id order by emp_id) as RN from emp)
      delete from cte where RN > 1

  • @vlog.444
    @vlog.444 5 місяців тому

    Bro good vide class Bren you have to increase your sound

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

    Ankit bhai if you have time can you solve some hacker rank test questions for better understanding for people who are learning sql newly..that would be helpfull

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

      Do you have some links to the good problems?

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

    hi Ankit , can you please make some videos for product based companies. Thank yoou for your effort. Appriciatable

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

      I have a lot of them. Check out complex SQL playlist

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

    please make a part 2 of this video Ankit.
    thank you for your efforts

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

    Thanks for this Video. I have one doubt, Question number 2. How to delete duplicates from a table? Shall we do it in mysql? I tried but I didn't get correct result.

  • @gouthamstar6558
    @gouthamstar6558 8 місяців тому

    I asked a question a employee enters and leaves office and he swipes in and swipes out in multiple instances, so I want to find the total office hours he spent in the office( he may come at 10 PM and take a break at 12:30 AM in that case it shows that he is spending 2 hours in that day but that's not true right), so now I have to calculate total time he spent
    employee id, Office_swipe_record given

  • @bhartisingh3750
    @bhartisingh3750 7 місяців тому

    Delete duplicate records query in not working in databricks notebook for deleting duplicate records from a table.. is there any way to do this in databricks notebook table?
    @ankit

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

    Thanks for this!

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

    Thanks brother, nice explanation

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

    Beautiful presentation

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

    Hi Ankit, what if I have same rows with all same values in 2 rows, how can I do that.? As the code you explained is not working in MySQL workbench. Thanks!

    • @SubhamDas-tb3xf
      @SubhamDas-tb3xf 6 місяців тому

      1. We might need the primary key in the original table. Without that how can you tell database which record to delete, if you can anyhow tell database 😂 that delete the records which I mentioned it will be exactly same as duplicates so everything will be deleted.
      First u need to assign primary key.
      2. MySQL 8+ versions doesn't support deleting data from cte( it's a temporary result set so logically it should not change the original table. Not sure about ssis implementation. ) so u have to reference the original table after selecting duplicate records u gotta tell database to delete those using a subquery.
      Do this:
      With cte as
      (Select * , row_number() over(partion by all the columns names) as rn
      From Ur_table_name)
      Delete from ur_table_name where id in (select * from cte where rn > 1)

  • @RK-wf7re
    @RK-wf7re Рік тому

    Good content, i have a question why table name used as emp1, it should be emp right?

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

    Your approach to Delete duplicate valuse from the table is not working in my sql (gettting this pop up "The target table cte1 of the DELETE is not updatable")

  • @manjumohan7731
    @manjumohan7731 Рік тому +2

    #For swap gender :
    update orders
    set customer_gender=IF(customer_gender='Male','Female','Male');

  • @amangupta1959
    @amangupta1959 2 роки тому +2

    Hi Ankit, the only doubt I have is while deleting duplicate records, we deleted from CTE and not actual employee table, how records were deleted from emp table?

    • @ankitbansal6
      @ankitbansal6  2 роки тому +2

      Hi Aman , glad you asked this question. Since the CTE is referring to the table directly, it was possible. This might not be possible in all the databases but works in SQL server.

    • @amangupta1959
      @amangupta1959 2 роки тому +3

      @@ankitbansal6 Right. I tried and even the below query is not working in MySQL.
      DELETE FROM (select *, row_number() over(partition by empno) as rn from emp)
      where rn>1;

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

      @@ankitbansal6 Hi Ankit, I am also facing same issue. I assume CTE will delete from parent table. it fails with "The target table CTE of the DELETE is not updatable
      "

    • @ankitbansal6
      @ankitbansal6  2 роки тому +2

      @@DataRevolution10 it works only in SQL server

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

      +1

  • @nitinnagpalofficial
    @nitinnagpalofficial 2 роки тому +2

    Ankit, I love your educational content. Is it possible for you to record the whole PL/SQL course for beginner/Intermediates?

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

      Thank you. I will plan in future 🙂

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

    In the 2 question, delete from cte is written so how the records got deleted from original table

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

    Thanks

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

    Just wanted to know can we use left anti join for the 5th question?

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

    Diff between count* and count1

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

    Hi Ankit , i start following your tutorial , it is really helpful . nut i am not able to connect SSMS at my local computer , can you please help me what should be server name . i am using SSMS 2019

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

      Localhost

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

      Make sure you have installed SQL server as well. ssms is just a client to access data base

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

    finished watching