Lec-63: SQL Queries and Subqueries (part-5) | Database Management System

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

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

  • @rinkirathore6502
    @rinkirathore6502 5 ปีที่แล้ว +935

    I think the appropriate query would be this one:
    Select E_name,dept, salary
    From emp
    where (dept , salary) IN
    (Select dept, max(salary)
    From emp
    Group by dept )

    • @sunidhidwivedi2181
      @sunidhidwivedi2181 5 ปีที่แล้ว +4

      Ya right, but sir ne sabse pehle sirf salary likha tha inner query me so it's acc to that.

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

      Correct buddy.

    • @Staytruegoggins
      @Staytruegoggins 5 ปีที่แล้ว +47

      @@sunidhidwivedi2181 what happens when 2 depts have same max salary

    • @alkeshkumar2227
      @alkeshkumar2227 5 ปีที่แล้ว +1

      Ya right dude 🤘

    • @williamhunter7131
      @williamhunter7131 5 ปีที่แล้ว +14

      Also the final query doesnt result in the same output that was asked in the question. I really liked some of his videos but these are not for software developers in my opinion but for someone who just wants to clear a test. Good enough for those scenarios i believe :)

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

    I think the appropriate query would be this:
    select E_name from emp where (dept,salary) in (select dept ,max(salary) from emp group by dept);

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

      Thanks

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

      وماذا لو كان هناك تشابه في القيم (نفس الأجر)ستكون النتيجة خاطئة

  • @jahangirahmed8813
    @jahangirahmed8813 5 ปีที่แล้ว +8

    Your video clips help me a lot to understand the concept of SQL. Before this, I knew nothing about queries. I understand easily what you teaches. God bless u.

  • @prateeksachdeva1611
    @prateeksachdeva1611 2 ปีที่แล้ว +7

    Your videos on sql are really the ones which can clear the doubts of any person on this particular topic. thanks sir!

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

    The correct query should be (tested):
    Select Ename, Salary from Emp where (Dept, Salary) In (Select Dept, Max(Salary) from Emp group by Dept);

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

      Yes it's correct, but what's wrong with the query that he has explained. Why it is not generating desired results as it seems to be correct as well.

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

      @@abhayjaswal3207 watch the concepts of "group by" clause you'll get whats wrong.....

    • @aakshatmalhotra8088
      @aakshatmalhotra8088 2 ปีที่แล้ว +11

      @@abhayjaswal3207 well if the highest salary of one dept is equal to normal salary of other dept, it would also the print the data where the salary is not highest but equal to highest salary of some dept.

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

      Thanks

    • @jeemath4502
      @jeemath4502 11 หลายเดือนก่อน

  • @satviknema8629
    @satviknema8629 4 ปีที่แล้ว +40

    Sir add this extra tuple in the table: [6 | Harry | IT | 40000]
    According to our query, we will get the output as:
    Ravi
    Nithin
    Varun
    Harry
    Whereas the answer should have been:
    Ravi
    Nithin
    Varun
    I think the error here is, we are only filtering on the basis on salary alone. It maybe possible that one department's highest salary is equal to other department's salary (which is not max in that department). In this example, highest in IT is 50k (Varun), and highest in MRKT is 40k (Nithin). Now Harry is in IT, whose salary is 40k, which is same as the maximum of MRKT, but not the maximum of IT. Hence it also got included in the answer
    The solution for this can be, in the outter query, we also add department along with the salary for filtering, such that only the maximum salary with that particular department is included.
    The proper query can be:
    Select ename
    from emp where (dept , salary) IN
    (select dept, max(salary)
    from emp
    group by dept )

    • @harshshah9962
      @harshshah9962 4 ปีที่แล้ว +1

      Greatly explained thnaks 😄😄

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

      perfect!

    • @LV-ni6tf
      @LV-ni6tf 3 ปีที่แล้ว

      I Hv doubt on this but now cleared thank all.

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

      th-cam.com/video/QTaiF8N6i3Y/w-d-xo.html

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

      th-cam.com/video/QTaiF8N6i3Y/w-d-xo.html🙏🏻

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

    The right answer for this is
    Select e_name , dept, salary from emp
    where (dept, salary) IN
    (Select dept, Max(salary) from emp GROUP BY dept) ;

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

      will this query work? - select dept, e_name, max(salary) from emp
      group by dept, e_name;

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

      ​@@ankush_in_sync5998nope cause we can use only aggregate function or the attribute which is used for group by after the select

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

    This will also work
    SELECT E_name
    FROM EMP
    WHERE (Dept,Salary) IN (SELECT Dept,Max(Salary)
    FROM EMP
    GROUP BY Dept)

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

      th-cam.com/video/QTaiF8N6i3Y/w-d-xo.html

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

      th-cam.com/video/QTaiF8N6i3Y/w-d-xo.html🙏🏻

  • @OmitA25
    @OmitA25 6 ปีที่แล้ว +6

    no .of rows in output = no. of rows in table A i.e 3 .........................very nice explanation ........sir upload more videos on it...

    • @GateSmashers
      @GateSmashers  6 ปีที่แล้ว

      Thanks Om..Sure we will..Keep learning and sharing..

  • @weslyworld
    @weslyworld 5 ปีที่แล้ว +4

    These guys are teaching us for free, spending all their time and energy and there are morons who spend their time to dislike such videos. Let's be humans guys and appreciate such genuine efforts. Dislikers kindly rethink.

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

      This video had a mistake, which still hasn't been rectified yet, maybe because of that the dislikes were more on this one.

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

    my version of query:
    select a.ename, a.salary from emp as a, (select dept as dept, max(salary) as salary from emp group by dept) as b where a.dept = b.dept and a.salary = b.salary;

  • @Naturelover-hc5un
    @Naturelover-hc5un 2 ปีที่แล้ว +1

    Inner the flow of your videos we are forgotten to like your videos the videos 😅😅😅

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

    Here I think , department and salary columns should be added in where and then we can department wise highest salary or else result will have repeatative department wise salary.
    Select * from emp where ( dept , salary) in (select dept , max( salary) from emp group by dept )

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

    Best vedio ever seen everything is cleared in sql.Thank you Sir.

  • @dkg4975
    @dkg4975 4 ปีที่แล้ว +5

    I think this is enough since group by displays only a single tuple from each group :)
    select emp,max(salary),dept
    from emp
    group by dept

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

      you cant use other attributes with group by, but only in aggregate functions

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

      th-cam.com/video/QTaiF8N6i3Y/w-d-xo.html

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

    select emp_name,dept_name,salary from employee
    where salary in (select max(salary) from employee group by dept_name)
    order by salary desc
    OR
    select max(salary),dept_name from employee
    group by dept_name
    order by salary desc

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

      Man you are a lifesaver!
      The Query worked really smooth!
      Thanks!

  • @martujahosen9903
    @martujahosen9903 4 ปีที่แล้ว

    Thanks for share this video

  • @_MilonPaul
    @_MilonPaul 2 ปีที่แล้ว +1

    thank you sir given explantion sub query.

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

    This is the right query. This will give you the name, salary, and department of the employees who earn the most in each department. If there are multiple employees in the same department with the same highest salary, they will all be included in the result.
    SELECT e.first_name, e.salary, d.department_name
    FROM employees e
    JOIN departments d ON e.department_id = d.department_id
    WHERE (e.department_id, e.salary) IN (
    SELECT department_id, MAX(salary)
    FROM employees
    GROUP BY department_id
    );

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

    Select ename,dept from emp where salary IN (Select MAX(salary) from emp group by dept);
    this will print ename,dept,salary in alongside manner

  • @ankanmazumdar5000
    @ankanmazumdar5000 4 ปีที่แล้ว +2

    Please find the more sensible query as there can same employees getting same salaries in different dept.-
    select ENAME, salary, DEPT
    from (
    select *
    , DENSE_RANK() over(partition by DEPT order by salary desc) as Highest_sal
    from EMP11
    ) a
    where a.Highest_sal = 1

  • @1311sourabh
    @1311sourabh 2 ปีที่แล้ว

    The right query is
    select e_name from emp
    where (dept,salary) in (select dept,max(salary) from emp group by dept);

  • @surendrasinghrajput6243
    @surendrasinghrajput6243 6 ปีที่แล้ว +41

    Sir this query have a drawback.
    The query which u wrote also gives those employee names who have the salary 30000,40000,50000 even the employee has not max salary in their department.

    • @sharadsharma4206
      @sharadsharma4206 6 ปีที่แล้ว +2

      Maybe, in the outer query, we can also add another condition of checking the dept name of outer and inner query along with salary. Then I think this problem will not exist.

    • @rahulzirpe9284
      @rahulzirpe9284 5 ปีที่แล้ว +1

      Exactly correct

    • @warriorteja6002
      @warriorteja6002 5 ปีที่แล้ว

      Anyone has solution for this using correlated subquery

    • @ankitatripathi9743
      @ankitatripathi9743 5 ปีที่แล้ว

      yeah true..

    • @mohitsoni6603
      @mohitsoni6603 5 ปีที่แล้ว +12

      Yes, you are correct.
      Check if this might work -
      select e_name,dept,salary from employee
      where (dept,salary) in (select dept,max(salary) from employee group by dept);

  • @Imrajeshsandhuvlogs
    @Imrajeshsandhuvlogs 4 ปีที่แล้ว +1

    Well explained and more class expect sir...... This section...sql....

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

    Sir I think if there is someone with 30000 in IT his name will also be printed even though highest is 50000 in IT

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

      Same ques? May be someone else with other dept have salary equal to tha max salary of other dept .

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

      Exactly...

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

      Please give correct solutions

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

      select max(salary),dept_name, emp_name from employee
      group by dept_name
      order by salary desc

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

      this will run in all cases

  • @chetnawadhwa4345
    @chetnawadhwa4345 6 หลายเดือนก่อน

    Very informative video 👍🏻 thank you ✌🏻

  • @sanskritijain2357
    @sanskritijain2357 4 ปีที่แล้ว +2

    Thank you sir....

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

    great explaination

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

    Ans is : select e_name , dept , salary from emp where (dept,salary) in (select dept,max(salary) from emp group by dept);

  • @techstra2k199
    @techstra2k199 5 ปีที่แล้ว +5

    SELECT name,salary,dept
    FROM emp
    where (dept,salary) in
    (SELECT dept,max(salary)
    FROM emp
    group by dept);
    This one will be the right query................... I assume some features.

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

    I'm Wasting my fees in university To be honest ...you're real GEM .. Much Respect From Pakistan

  • @architjindal908
    @architjindal908 4 ปีที่แล้ว +16

    select* from emp where concat (dept, " ",salary) in (select concat (dept," ",max(salary)) from emp group by dept)
    This query will work in all cases.
    Suggest me any test case if I am wrong.

  • @MountainCR7
    @MountainCR7 5 ปีที่แล้ว +1

    Aap bhaut payar se samjhate hai

  • @jatinsingh1368
    @jatinsingh1368 2 ปีที่แล้ว +1

    The Correct query is :
    Select Fname, Salary from employee where (Dno, Salary) In (Select Dno, Max(Salary) from employee group by Dno);
    Explaination :-
    the the inner query will give us the pairs , now outer query will take that pairs and will check if(Dno==Dno && Salary==Salary) and then will give us the output

  • @soumyanayak2898
    @soumyanayak2898 5 ปีที่แล้ว

    select name,salary,dept from emp a where salary in (
    select max(salary) as max_salary from emp b
    where a.dept=b.dept
    group by dept )
    OR
    select a.name,a.salary,b.dept from emp a inner join
    (select dept,max(salary) as salary from emp group by 1) b on (a.dept=b.dept and a.salary = b.salary)

  • @priyanagori9837
    @priyanagori9837 4 ปีที่แล้ว

    Excellent

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

    select ename from emp where (dep,salary) IN( select dep,MAX(salary) from emp GROUP BY dep );

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

    Sir your quary is only showing the names who are taking Max salary.
    But as per your question it should be shown highest salary, dept, and E name.
    (Tasted in Microsoft SQL server)

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

    This query will work :
    select Distinct e_name,dept,salary from emp where (dept , salary) in (select dept,max(salary) from emp group by dept);

  • @richenjoshi7054
    @richenjoshi7054 10 หลายเดือนก่อน

    select E_name, salary
    from Emp
    where dept in
    (select dept from Emp group by dept having max(salary));

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

    sir...u r fab :)

  • @farazahmad3959
    @farazahmad3959 4 ปีที่แล้ว

    Select E_name,dept, salary
    From emp
    where salary IN
    (Select max(salary)
    From emp
    Group by dept );

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

    Select emp name where salary = (Select max(salary) , department from emp group by department id)

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

    You explained expected scenario in very easy way :)

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

    Observe carefully
    Query framed by Varun Sir is absolutely right

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

    Hello Varun. First, thanks for creating these videos. Now, kindly tell us a query where we can display the name of employees drawing hishest salary, Dept name and salary simultaneously in a single query. Thanks bro.

  • @vibha6613
    @vibha6613 6 หลายเดือนก่อน

    Time [ 8:30 ] Query :-
    SELECT ENAME, DEPT, SALARY FROM EMP WHERE (DEPT,SALARY) IN (SELECT DEPT,MAX(SALARY) FROM EMP GROUP BY DEPT);

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

    Outstanding work thank you 🙏

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

    Dept should be there in the select of subqurey because group by attribute should be included in select...

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

    My approch was-
    Select dept, salary
    From employee
    Group by dept having max(salary)

  • @suchetabhatia4473
    @suchetabhatia4473 4 ปีที่แล้ว +1

    Thanku sir

  • @meenakshigarg340
    @meenakshigarg340 4 ปีที่แล้ว

    Very nice sir

  • @fitking1234
    @fitking1234 10 หลายเดือนก่อน +1

    Sir is query ma issue ye a skta k agr kisi or dept k bndy ki salaray chahty kuch bhi ho agr wo match kr jaye kisi or dept k max salaried employee sa to us ka data bhi print ho jana.
    Correct me if I am wrong.
    Anyways amazing lectures and quality.

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

    Sir the query for the given question is not correct as if consider the case when the salary of two person of different department is equal and one of them is having a highest salary in it's department. So when the given query is executed, it will display the name corresponding to the highest salary of that department along with the name of other person having the same salary but different department which is not the highest.

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

    As per question answer should be::
    select PERSON_NAME,DEP_ID,sal from employee where (DEP_ID,sal) in (select DEP_ID,max(sal) from employee group by DEP_ID);

  • @sajansekhu8785
    @sajansekhu8785 5 ปีที่แล้ว

    thnkss alott ji..u r the great ji...God bless u forever....🙏🙏🙏🙏🙏🙏

  • @namratanikam7566
    @namratanikam7566 4 ปีที่แล้ว

    Very well explained😊

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

    You are the best ❤️😌

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

    Fire ho app🔥🔥

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

    Select emp name where salary in (Select max(salary) , department from emp group by department id)

  • @owaisali995
    @owaisali995 5 ปีที่แล้ว +1

    I think you dont need to put inner query this will work fine.. Select Dept,emp_Name,Max(Salary) from Employee group by Dept,emp_name; This query wll give you name of employee with max salary in each department.

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

      when you group by emp_name then actually each rows will be considered as a seperate group...so,all the salaries will be returned in the mas(sal) column...and it will be same as the original table...

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

    love u sir u are great like me ...b/c u were creating video i am following sequence now, i am at video number 62..

  • @weslyworld
    @weslyworld 5 ปีที่แล้ว

    Btw i subscribed and will recommend your channel to my contacts. Super Like.

  • @madhuparnadebnath9061
    @madhuparnadebnath9061 6 หลายเดือนก่อน

    Thank you so much sir

  • @hafsakhalil7458
    @hafsakhalil7458 5 ปีที่แล้ว

    V v v vv good sir g

  • @akshayakumar823
    @akshayakumar823 5 ปีที่แล้ว

    If the highest salary of one department is the lowest salary of another department then also that employeename will be printed . It would work well if we take department name with max salary inside IN

  • @RohitKumar-xu5my
    @RohitKumar-xu5my 4 ปีที่แล้ว +2

    Thank you so much sir now I am confident writing queries. 👍

  • @deshrajyadav7823
    @deshrajyadav7823 5 ปีที่แล้ว

    Thank u so much its very important for 10 class also

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

    Thank you sir ☺️

  • @ryanmarian1038
    @ryanmarian1038 4 ปีที่แล้ว

    THANKS A LOT SIR

  • @arnavraj4293
    @arnavraj4293 4 ปีที่แล้ว +1

    at around 10:00,, maybe there be chances that more than one dep. having the same maximum salary,,,,, what about that case? selecting name in that case may work differently

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

    I think this solution is Partially right only becoz if an employee from a department is taking minimum salary in that department but that salary is maximum in some other department then his name will be printed which is wrong.

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

    hats off!

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

    BHAI MAI APKEY VIDEOS HAMESHSA FOLLOW KARTHA HU AND I LIKE THE WAY U TEACH US I HAVE LIL DOUBT WHILE IM APPLYING TO GET NAME OF EMP ITS SHOWING SYNTAX ERORR HOPE U WILL SEE MY COMMENT LOVE U BRO FROM ANDHRA PRADESH❤

  • @jobsnews615
    @jobsnews615 10 หลายเดือนก่อน

    this wrong right is :- select ename ,concat(salary+dept)from employee where concat(salary,dept) in (select concat(max(salary),dept) from employee group by dept);

  • @animationcrust1993
    @animationcrust1993 4 ปีที่แล้ว

    Best teacher you are ❤️🤗

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

    We can use order by if we are not using sub queries

  • @bibekkc5142
    @bibekkc5142 5 ปีที่แล้ว +1

    love you sir from nepal...

    • @gaurav01911
      @gaurav01911 4 ปีที่แล้ว +1

      nepali apna map thik kra lo...boht pele jaoge warna

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

      @@gaurav01911 haha

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

    I used 'JOIN' to get the desired output instead of nested query - not sure how nested query works here.
    -- create a table
    CREATE TABLE students (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    dept TEXT NOT NULL,
    salary INT not null
    );
    -- insert some values
    INSERT INTO students VALUES (1, 'Ryan', 'IT', 10000),(2, 'Joanna', 'MRKT', 20000),
    (3, 'Ravi', 'HR', 30000), (4, 'Nitin', 'MRKT', 40000), (5, 'Varun', 'IT', 50000),
    (6, 'Shivam', 'MRKT', 30000);
    -- fetch some values
    Select S.name, S.dept, S.salary
    From students as S
    JOIN (Select dept, max(salary) as salary From students Group by dept) as T
    on S.dept = T.dept
    and S.salary =T.salary;

  • @Mukthar_vlogs
    @Mukthar_vlogs 4 ปีที่แล้ว

    Thanks 😊

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

    subscribed and belled . very detailed

  • @ranjeetakaurmatharu6007
    @ranjeetakaurmatharu6007 6 ปีที่แล้ว +4

    #Gate Smashers
    Sir in this question query is to write highest salary dept wise and with name
    But
    In the given sol it's just giving the name?

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

      Both are different parts of the question. If you want highest salary with name then you can use
      select name,salary from emp where salary IN (select max(salary) from emp group by dept);

    • @ranjeetakaurmatharu6007
      @ranjeetakaurmatharu6007 6 ปีที่แล้ว +1

      @@GateSmashers thank you so much sir ur lessons r too good... 🙏

  • @Namisha971
    @Namisha971 4 ปีที่แล้ว

    Please make video on software engineering n data structure

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

    Select dept,max(salary),ename from employee group by dept,salary; query likh sakte hai kya

  • @jiteshkumar3112
    @jiteshkumar3112 4 ปีที่แล้ว +1

    Sir outer query me select e_name,salary ayega shaayd because hme dono haiye output me

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

    What if we have two tables separately, in which one table contain employee salary, name then other table contain department name and common attribute is dno

  • @095_shaniabalkhi9
    @095_shaniabalkhi9 ปีที่แล้ว

    This should be the correct query (tested) -
    SELECT E_NAME, SALARY
    FROM EMP
    WHERE SALARY IN
    (
    SELECT MAX(SALARY)
    FROM EMP
    GROUP BY DEPT
    );

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

    hats offff u sir

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

    You are amazing man. Thank you so much for your lovely sessions. I particularly like the punjabi flavour in your Hindi. These sessions have been of so much use to people like us. May you always stay healthy and happy. Coud you make a few sessions on SQL queries that are frequently used by manual testers. Would be of a great great help. Thank you once again from the bottom of my heart. Let us know your name dude.

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

    If table is
    Ram-HR-10000,ravi-HR_20000,shiv-IT-10000
    Then this query would fail
    Coz inner query will return (10000,20000)
    N here ram also get 10000 but that is not maximum salary in his dept

  • @tokyostreams7982
    @tokyostreams7982 11 หลายเดือนก่อน

    What if Amrit salary was 30000 Then Amrit name will also be displayed because 30000 is IN the subquery. But from marketing department Nitin is taking maximum salary and not Amrit. So the query what sir told doesn't display name department. It just display the name who are taking max salary. And not who are taking max salary in particular department. Correct me if I'm wrong.

  • @snipereagle6872
    @snipereagle6872 4 หลายเดือนก่อน

    Query provided by you sir is wrong. Correct query is : SELECT e.E_name, e.dept, e.salary
    FROM emp e
    JOIN (
    SELECT dept, MAX(salary) AS max_salary
    FROM emp
    GROUP BY dept
    ) d
    ON e.dept = d.dept AND e.salary = d.max_salary;

  • @ritikbansal9677
    @ritikbansal9677 18 วันที่ผ่านมา

    but sir wasn't the use use of dept necessary if we use group by dept??

  • @javariddles1189
    @javariddles1189 6 ปีที่แล้ว

    Thanks

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

    correct me if im wroung im righting this query expectinf there is reduntant data in salary :
    select e_name from emp where salery in(select max(salary from group by dept) and where dept in (select dept from group by dept)

  • @nihalsingh5558
    @nihalsingh5558 6 ปีที่แล้ว

    Sir plzz upload more videos on more complex queries

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

    sir what will happen if one more tuple is there in employee table whose salary is 40,000 and department is IT.this query will print that name also

  • @koushikjana849
    @koushikjana849 5 ปีที่แล้ว +14

    If any condition HR maximum salary 30,000 and MRKT minimum salary 30,000 who's E_name are printed in this queries

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

      Obviously it will not work in this query

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

      Then may be we have to compositly check the dept and salary both after finding group by max salary of each department

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

      Thank you sir

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

      Then it will show the the name corresponding to highest salary in MRKT

  • @arpita3342
    @arpita3342 4 ปีที่แล้ว +2

    Hello Sir, I have one doubt on this final query to find names of emp who having highest salary dept wise.
    Suppose, a emp working on MRKT whose salary is 30,000 (but in MRKT dpt highest salary is 40,000) . According to this query that emp name also come to output as that 30,000 value is in the inner query.
    Kindly please help me to clear my doubt.

  • @aalirashid7178
    @aalirashid7178 4 ปีที่แล้ว

    SQL>
    select first_name from worker2 where salary in(select department,max(salary) from worker2 group by department)
    *
    ERROR at line 1:
    ORA-00913: too many values
    "I am having this error in oracle 11g". Cant resolve.