SQL Interview Question Answers

1) Display details of all employees
SQL> select * from emp;

2) Display the employee no and totalsalary for all the employees. Here totalsalary = sal+comm
SQL> select empno,ename,sal,comm, sal+nvl(comm,0) total_sal from emp;

3) Display the names of all the employees who are working in department 10.
SQL> select emame from emp where deptno=10;

4) Display the employee number and name who are earning comm.
SQL> select empno,ename from emp where comm is not null;

5) Display the names of the employees who are working in the company for the past 5 years;
SQL> select ename from emp where hiredate < add_months(sysdate,-60);

6) Display the names of employees working in department number 10 or 20 or 40 and working as CLERKS,SALESMAN or ANALYST.
SQL> select ename from emp where deptno in(10,20,40) and job in('CLERKS','SALESMAN','ANALYST');

7) Display the Employee names for employees whose name ends with alaphabet S.
SQL> select ename from emp where ename like '%S';

8) Display the maximum salary being paid to CLERK.
SQL> select max(sal) from emp where job='CLERK';

9) Display the total salary drawn by an ANALYST working in department 40.
SQL> select sum(sal) from emp where job='ANALYST' and deptno=40;

10) Display the department numbers with more than three employees in each dept.
SQL> select deptno,count(deptno) from emp group by deptno having count(*)>3;

11) Display the name of the employee who earns highest salary.
SQL> select ename from emp where sal=(select max(sal) from emp);

12) Display the employee number and name for employee working as clerk and earning highest salary among clerks.
SQL> select empno,ename from emp where where job='CLERK' and sal=(select max(sal) from emp where job='CLERK');

13) Display the names of the employees who earn highest salary in their respective departments.
SQL> select ename,sal,deptno from emp e where sal in(select max(sal) from emp m where m.deptno = e.deptno);

14) Display the current '15-Aug-2012' as 15th wednesday August twenty twelve.
SQL> select to_char(to_date('15-Aug-2012'),'ddth day Month year') from dual;

15) Display the Employee name and Managers names.
SQL> select e.ename employee, m.ename manager from emp e, emp m where m.empno=e.mgr;

16) Find out top 5 earners of company.
SQL> select * from (select * from emp order by sal desc) where rownum <= 5;

17) Display the department name and total number of employees in each department.
SQL> select dname, count(ename) from emp, dept where emp.deptno=dept.deptno group by dname;

18) Increase salary of all managers by 10%.
SQL> update emp set sal=sal*1.1 where empno in (select mgr from emp);

19) Delete duplicate department from dept table.
SQL> delete from dept where rowid not in (select max(rowid) from dept group by dname);

20) Create a backup of employee table with emp_tbd name
SQL> create table emp_tbd as select * from emp;

21) Get the details of the employee getting 3rd highest salary
SQL> select * from(select e.*, dense_rank() over (order by sal desc) r from emp e) where r=3;

22) Get the details of the employees getting department wise 3rd highest salary
SQL> select * from(select empno, ename, sal, dname, dense_rank() over (partition by dname order by sal desc) r from scott.emp e, scott.dept d where e.deptno=d.deptno) where r=3;

For Questions related to C Programming: http://cbasicprogram.blogspot.in/

Related Posts
- Difference Between Cursor And Ref Cursor
- Query optimization tips for Oracle
- How to connect SQLPlus without tnsnames.ora
- Oracle Database 12c New Features for Developers
- JSON in Oracle Database with Example
- New Features for Developers in Oracle 11g
- Top 15 new features of Oracle Database 12.2 for developers

34 comments:

  1. it is very nice perfect notes for begi...

    ReplyDelete
    Replies
    1. Keep coming for other useful posts under "Oracle SQL" tag

      Delete
  2. This type of "quick reference" is very useful, thanks for sharing!

    ReplyDelete
  3. Nash Somaroo - South AfricaSeptember 3, 2012 at 5:00 PM

    Thank you, Thank you, Thank you.
    Your notes are extremely helpful to assist a beginner in Oracle.

    ReplyDelete
    Replies
    1. Glad that it helped you, keep visiting for more useful posts.

      Delete
  4. Thanks nimish - great for beginners! Found some good ones that are more advanced here:

    Complex sql interview questions

    ReplyDelete
  5. Hi ! can anyone explain me about pragma init? I have gone through some articles but I am not able to understand.

    Thanks in advance

    ReplyDelete
    Replies
    1. check this link: http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/errors.htm#i1863

      Delete
  6. Good stuff, all pretty straightforward but number 14 is wrong

    14) Display the current '15-Aug-2012' as 15th wednesday twenty twelve.
    SQL> select to_char(to_date('15-Aug-2012'),'ddth Month year') from dual;

    You would need to specify "day" to output "wednesday"

    ReplyDelete
    Replies
    1. and also in question i forgot to specify august :) thanks !!!

      Delete
  7. hi, I want a query, i have emp and dept table. both table having empid .I want a query to the show id whose empid is holding all dept name.

    ReplyDelete
    Replies
    1. Do you mean, you want to search a employee who is member of all the departments ?

      Delete
    2. SELECT E.EID,D.EID FROM EMP E,DEPT D WHERE E.EID=D.EID;

      Delete
  8. Hi,can u please send me questions on subquery

    ReplyDelete
  9. helpful for beginner......

    ReplyDelete
  10. You can Visit for more Different kinda C-Patterns And C-Programs.
    https://www.thecprograms.com/

    ReplyDelete
  11. But he's trying none the less. I've been using Movable-type on a variety of websites for about a year and am nervous about switching to another platform. I have heard good things about . Is there a way I can import all my word press posts into it? Any help would be really appreciated!

    야한소설

    ReplyDelete
  12. Adapted to new systems and processes well and seeks out training to enhance knowledge, skills and abilities.

    스포츠마사지

    ReplyDelete
  13. Not that I am complaining, but slow loading instances times will sometimes affect your placement in google and could damage your high-quality score if advertising and marketing with AdWords. Well I am adding this RSS to my e-mail and can look out for a lot more of your respective fascinating content.

    출장마사지

    ReplyDelete
  14. I came to this site with the introduction of a friend around me and I was very impressed when I found your writing. I'll come back often after bookmarking! casinocommunity

    ReplyDelete
  15. It s a very useful page. Thank you. 2c598a47deefadd6afe78d4cdc92b537
    torbali
    efeler
    karakopru
    keciborlu
    yomra
    cekerek
    ardesen
    yesilyurt
    kemalpasa

    ReplyDelete
  16. Congratulations on your article, it was very helpful and successful. 3b3ea83d4a6a0c98c6235096f1c85925
    website kurma
    sms onay
    website kurma

    ReplyDelete
  17. Thank you for your explanation, very good content. 6695aa8fc7689bc87700189db0f0c688
    define dedektörü

    ReplyDelete
  18. جراحی بینی استخوانی بسته به اینکه جراحی شما چقدر پیچیده باشد و جراح شما چه چیزی را ترجیح می دهد نیاز به بی حسی موضعی همراه با آرامبخش یا بیهوشی عمومی دارد. قبل از جراحی با پزشک خود صحبت کنید که کدام نوع بیهوشی برای شما مناسب است.
    جراح شما می تواند شکل استخوان یا غضروف بینی شما را به روش های مختلفی بسته به میزان نیاز به برداشتن یا اضافه کردن، ساختار بینی و مواد موجود تغییر دهد. برای تغییرات کوچک، جراح ممکن است از غضروف هایی که از عمق بیشتری از داخل بینی یا گوش گرفته شده استفاده کند. برای تغییرات بزرگتر، جراح می تواند از غضروف دنده، ایمپلنت یا استخوان سایر قسمت های بدن شما استفاده کند. پس از ایجاد این تغییرات، جراح پوست و بافت بینی را به عقب قرار می دهد و برش ها را در بینی شما بخیه می زند.
    اگر دیواره بین دو طرف بینی (سپتوم) خم یا کج (انحراف) باشد، جراح نیز می تواند آن را برای بهبود تنفس اصلاح کند.
    پس از جراحی، شما در اتاق ریکاوری خواهید بود، جایی که کارکنان بر بازگشت شما به حالت بیداری نظارت می کنند. ممکن است همان روز آن جا را ترک کنید یا اگر مشکلات سلامتی دیگری دارید، ممکن است یک شب بمانید.
    انتخاب دکتر متخصص برای عمل‌های زیبایی یکی از مهم‌ترین برای گرفتن نتیجه‌ی بهتر است. در نتیجه، قبل از عمل حتما برای انتخاب بهترین دکتر تحقیق کنید و نمونه کارهای دکتر را ببینید.
    با دکتر کامبیز ایزدپناه فوق‌تخصص جراحی پلاستیک، ترمیمی و زیبایی، از نتیجه‌ی عمل خود آسوده خاطر خواهید بود. دکتر عضو سازمان نظام پزشکی ایران، عضو جامعه جراحان ایران و عضو انجمن جراحی پلاستیک ایران است. دکتر ایزدپناه تا زمان گرفتن نتیجه‌ی ایده‌آل کنار شما خواهند بود.

    ReplyDelete

  19. پیج اینستاگرام دکتر ایزدپناه
    drkambizizadpanah@

    برای مشاهده نمونه کارها و نظرات متقاضیان، اینستاگرام دکتر ایزدپناه
    ( فوق تخصص جراحی پلاستیک و زیبایی ) را دنبال کنید.

    چه درمانی برای جراحی بینی شکسته لازم است؟
    اگر شکستگی جزئی دارید که باعث کج شدن یا بدشکل شدن بینی شما نشده است، ممکن است نیازی به درمان پزشکی حرفه ای نداشته باشید. ممکن است فقط با استفاده از یخ روی ناحیه و مصرف داروهای مسکن بدون نسخه، خوب باشید.

    ReplyDelete
  20. معمولا رشد موهای سینه در بدن آقایان طبیعی است. بیشتر آقایانی که به بهداشت و زیبایی بدن خود اهمیت می‌دهند و اکثر آقایان ورزشکار مایل به لیزر موهای زائد سینه هستند. خانم‌ها معمولا کمتر دارای موهای زائد در ناحیه سینه هستند، البته نباید حساسیت به خرج داد و موی سینه باید واقعا زائد باشد و نه صرفا موی نازک. زیرا لیزر موی نازک به هیچ وجه انجام نمی‌پذیرد.
    لیزر موهای سینه مردان

    ReplyDelete