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

Поделиться
HTML-код
  • Опубликовано: 17 сен 2018
  • 👉Subscribe to our new channel: / @varunainashots
    ► Structured Query Language (SQL)(Complete Playlist):
    • Structured Query Langu...
    Other subject-wise playlist Links:
    --------------------------------------------------------------------------------------------------------------------------------------
    ►Design and Analysis of algorithms (DAA):
    • Design and Analysis of...
    ►Computer Architecture (Complete Playlist):
    • Computer Organization ...
    ► Theory of Computation
    • TOC(Theory of Computat...
    ►Artificial Intelligence:
    • Artificial Intelligenc...
    ►Computer Networks (Complete Playlist):
    • Computer Networks (Com...
    ►Operating System:
    • Operating System (Comp...
    ►Database Management System(Complete Playlist):
    • DBMS (Database Managem...
    ►Discrete Mathematics:
    • Discrete Mathematics
    ►Compiler Design:
    • Compiler Design (Compl...
    ►Number System:
    • Number system
    ►Cloud Computing & BIG Data:
    • Cloud Computing & BIG ...
    ►Software Engineering:
    • Software Engineering
    ►Data Structure:
    • Data Structure
    ►Graph Theory:
    • Graph Theory
    ►Programming in C:
    • C Programming
    ►Digital Logic:
    • Digital Logic (Complet...
    ---------------------------------------------------------------------------------------------------------------------------------------
    Our social media Links:
    ► Subscribe to us on RUclips: / gatesmashers
    ►Subscribe to our new channel: / @varunainashots
    ► Like our page on Facebook: / gatesmashers
    ► Follow us on Instagram: / gate.smashers
    ► Follow us on Instagram: / varunainashots
    ► Follow us on Telegram: t.me/gatesmashersofficial
    ► Follow us on Threads: www.threads.net/@gate.smashers
    --------------------------------------------------------------------------------------------------------------------------------------
    ►For Any Query, Suggestion or notes contribution:
    Email us at: gatesmashers2018@gmail.com

Комментарии • 389

  • @rinkirathore6502
    @rinkirathore6502 5 лет назад +890

    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 лет назад +45

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

    • @alkeshkumar2227
      @alkeshkumar2227 5 лет назад +1

      Ya right dude 🤘

    • @williamhunter7131
      @williamhunter7131 4 года назад +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 :)

  • @jahangirahmed8813
    @jahangirahmed8813 5 лет назад +7

    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.

  • @kediarahul4519
    @kediarahul4519 2 года назад +61

    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 Год назад

      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 Год назад

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

    • @aakshatmalhotra8088
      @aakshatmalhotra8088 Год назад +7

      @@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 7 месяцев назад

  • @amiteshraj2860
    @amiteshraj2860 3 года назад +21

    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 9 месяцев назад

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

  • @prateeksachdeva1611
    @prateeksachdeva1611 Год назад +7

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

  • @vardaansangar3568
    @vardaansangar3568 3 года назад +14

    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 11 месяцев назад

      ​@@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 года назад +15

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

  • @vishwanathgr2532
    @vishwanathgr2532 2 года назад +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 )

  • @sonialodhay
    @sonialodhay 2 года назад

    Outstanding work thank you 🙏

  • @Imrajeshsandhuvlogs
    @Imrajeshsandhuvlogs 4 года назад +1

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

  • @weslyworld
    @weslyworld 4 года назад +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.

  • @ritikrustagi
    @ritikrustagi 3 года назад +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.

  • @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;

  • @deshrajyadav7823
    @deshrajyadav7823 5 лет назад

    Thank u so much its very important for 10 class also

  • @ankanmazumdar5000
    @ankanmazumdar5000 3 года назад +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

  • @chetnawadhwa4345
    @chetnawadhwa4345 2 месяца назад

    Very informative video 👍🏻 thank you ✌🏻

  • @weslyworld
    @weslyworld 4 года назад

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

  • @sanskritijain2357
    @sanskritijain2357 4 года назад +2

    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 2 года назад

      ruclips.net/video/QTaiF8N6i3Y/видео.html

  • @pragyasharma463
    @pragyasharma463 5 лет назад +3

    sir...u r fab :)

  • @_MilonPaul
    @_MilonPaul 2 года назад +1

    thank you sir given explantion sub query.

  • @martujahosen9903
    @martujahosen9903 4 года назад

    Thanks for share this video

  • @namratanikam7566
    @namratanikam7566 3 года назад

    Very well explained😊

  • @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.

  • @OmitA25
    @OmitA25 5 лет назад +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  5 лет назад

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

  • @sambalryder
    @sambalryder 4 года назад +1

    so can i use directly aggregate functions for salary even if im using group by clause for the department?

  • @Naturelover-hc5un
    @Naturelover-hc5un 2 года назад +1

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

  • @morsheddld
    @morsheddld 5 лет назад

    subscribed and belled . very detailed

  • @samirgoyal4597
    @samirgoyal4597 3 года назад +3

    You explained expected scenario in very easy way :)

  • @madhuparnadebnath9061
    @madhuparnadebnath9061 2 месяца назад

    Thank you so much sir

  • @weslyworld
    @weslyworld 4 года назад +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.

  • @nimraayaz4361
    @nimraayaz4361 Год назад

    great explaination

  • @MountainCR7
    @MountainCR7 5 лет назад +1

    Aap bhaut payar se samjhate hai

  • @RohitKumar-xu5my
    @RohitKumar-xu5my 3 года назад +2

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

  • @subhasismondal3984
    @subhasismondal3984 3 года назад

    You are the best ❤️😌

  • @sayalipatil1229
    @sayalipatil1229 5 лет назад

    Thank u sir

  • @surendrasinghrajput6243
    @surendrasinghrajput6243 5 лет назад +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 5 лет назад +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);

  • @javariddles1189
    @javariddles1189 5 лет назад

    Thanks

  • @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)

  • @indiancoder8301
    @indiancoder8301 3 года назад +44

    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

  • @architnangalia3426
    @architnangalia3426 3 года назад +1

    In my database, i'm getting 12 rows for the inner query but when I apply the outer query, i'm getting 24 rows. How is that possible?

  • @suchetabhatia4473
    @suchetabhatia4473 4 года назад +1

    Thanku sir

  • @fitking1234
    @fitking1234 6 месяцев назад +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.

  • @priyanagori9837
    @priyanagori9837 4 года назад

    Excellent

  • @Huntyoudown2020
    @Huntyoudown2020 9 месяцев назад

    hats off!

  • @Mukthar_vlogs
    @Mukthar_vlogs 3 года назад

    Thanks 😊

  • @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

  • @thorgaming409
    @thorgaming409 3 года назад

    Thank you sir ☺️

  • @kidsstory2041
    @kidsstory2041 4 года назад +1

    Sir, if max salary for each group is same ,and name of the employees are different then how to retrieve those names..??

  • @utkarshpanwar2358
    @utkarshpanwar2358 5 лет назад

    how aggregate fun work on the group by clause after grouping into a group
    I am assuming when our table is grouped in to dept then how there is an occurrence of salary which is extracted by the aggregate function in above example

  • @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.

  • @shahinparween3496
    @shahinparween3496 3 года назад

    Thank you sir

  • @satviknema8629
    @satviknema8629 4 года назад +36

    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 3 года назад +1

      Greatly explained thnaks 😄😄

    • @ADITYAGAIKWAD
      @ADITYAGAIKWAD 2 года назад +1

      perfect!

    • @LV-ni6tf
      @LV-ni6tf 2 года назад

      I Hv doubt on this but now cleared thank all.

    • @rameshmalhotra9525
      @rameshmalhotra9525 2 года назад

      ruclips.net/video/QTaiF8N6i3Y/видео.html

    • @rameshmalhotra9525
      @rameshmalhotra9525 2 года назад

      ruclips.net/video/QTaiF8N6i3Y/видео.html🙏🏻

  • @wildanimal1058
    @wildanimal1058 10 месяцев назад

    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
    );

  • @siddharthshukla758
    @siddharthshukla758 2 года назад +1

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

  • @sadabansari741
    @sadabansari741 Год назад

    Fire ho app🔥🔥

  • @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..

  • @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)

  • @sajaljain2885
    @sajaljain2885 3 года назад +1

    bhaiya agar sub query me dept bhi add krre hai to run nhi hora , too many values ara , why?

  • @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);

  • @hafsakhalil7458
    @hafsakhalil7458 5 лет назад

    V v v vv good sir g

  • @asha7699
    @asha7699 4 года назад

    hello sir
    in this query, if there r more than 1 employee, who is getting maximum salary than what will be the output????

  • @meenakshigarg340
    @meenakshigarg340 4 года назад

    Very nice sir

  • @akshayakumar823
    @akshayakumar823 4 года назад

    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

  • @jiteshkumar3112
    @jiteshkumar3112 4 года назад +1

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

  • @sahikumar8512
    @sahikumar8512 11 месяцев назад

    hats offff u sir

  • @richenjoshi7054
    @richenjoshi7054 7 месяцев назад

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

  • @vyshnaviyoj8802
    @vyshnaviyoj8802 5 лет назад

    sir, in the last query if 30000 salary may be one of the other dept candidate can also have in that case it will it retrieve that candidate name

  • @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

  • @kishansingh3994
    @kishansingh3994 3 года назад

    Sir what if maximum salary vale ka naam print karvana ho table mei. How will we do that if its not possible to use other column than dept in SELECT???

  • @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❤

  • @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);

  • @bint-i-akbar_foodshorts
    @bint-i-akbar_foodshorts 4 года назад

    👍👍

  • @owaisali995
    @owaisali995 4 года назад +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...

  • @nihalsingh5558
    @nihalsingh5558 5 лет назад

    Sir plzz upload more videos on more complex queries

  • @arnavraj4293
    @arnavraj4293 4 года назад

    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

  • @salimrajput2755
    @salimrajput2755 5 лет назад

    Pls tell us about platform for using SQL ,pls describe the link.....

  • @animeshhazra6061
    @animeshhazra6061 Год назад

    Nice

  • @amanpandey4550
    @amanpandey4550 2 года назад

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

  • @animationcrust1993
    @animationcrust1993 3 года назад

    Best teacher you are ❤️🤗

  • @vijayasimhareddy5672
    @vijayasimhareddy5672 2 года назад

    what if there is one more row with dept IT and person having 1000 salary ... it will aslo get printed ryt ? so it says that the query is wrong !!

  • @-CHEPURIVARUNSAI
    @-CHEPURIVARUNSAI 3 года назад

    sir, if hr and mrkt has same max salary will have any confusion?

  • @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);

  • @namankabadi2792
    @namankabadi2792 Год назад

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

  • @ChickenChaap
    @ChickenChaap Год назад +2

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

  • @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)

  • @ranjita2022
    @ranjita2022 8 месяцев назад

    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

  • @tokyostreams7982
    @tokyostreams7982 7 месяцев назад

    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.

  • @jprakashtoppo
    @jprakashtoppo 3 года назад

    Sir, I have a doubt
    What if there is another tuple in the table with data : E_id = 5, E_name = Mohan, Dept = IT, Salary = 40000
    then the person Mohan will also be in OUTPUT?
    Please, comment on this.

  • @mohitgupta7349
    @mohitgupta7349 2 года назад

    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

  • @yogeshrai8864
    @yogeshrai8864 5 лет назад +3

    suppose if we want to print all the information about RAVI
    then what is the format

    • @Paradise-kv7fn
      @Paradise-kv7fn 5 лет назад +1

      Yogesh Rai select * from employee where e_name = ‘ravi’

  • @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 2 года назад

      Obviously it will not work in this query

    • @yasharya8228
      @yasharya8228 2 года назад +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 2 года назад

      Thank you sir

    • @jayesh1891
      @jayesh1891 2 года назад

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

  • @akashayar3823
    @akashayar3823 2 года назад

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

  • @parvezshaikh2607
    @parvezshaikh2607 3 года назад

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

  • @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;

  • @pavanasnarayan2024
    @pavanasnarayan2024 2 года назад

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

  • @bibekkc5142
    @bibekkc5142 4 года назад +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

  • @alberteinstein2468
    @alberteinstein2468 4 года назад

    What if the Salary Column includes the following salaries as per the order- HR->10K, MRKT->30K, HR->30K, MRKT->50K, IT->50K. Then as per the query, we will get Highest Salaries as MRKT->30K, MRKT->50K, IT->50K...Which is wrong, Because HR(30K),MRKT(50K),IT(50K).. Please guide me..!

  • @sreepadaramakhilesh605
    @sreepadaramakhilesh605 4 года назад

    Sir yaha hr me highest salary 30000 h
    Agar sir mrkt me Amrit ka salary 30000 hota to jb ename find krre te tb 30000 ke liye do do names aate kya
    Or
    Kya jo ename h vo sirf salary k numbers se match krra h ya particular Dept me jo salary h usse match krra h?

  • @AbhishekSingh-fz6jp
    @AbhishekSingh-fz6jp 2 года назад

    Sir can we write like this
    Select ename, max (salary) from emp where dept in (select dept group by dept) order by salary