A database question encountered during the interview and a database encountered during the interview

Source: Internet
Author: User

A database question encountered during the interview and a database encountered during the interview

I have interviewed many organizations over the past few days and made some pen-related questions. I will recall and sort them out.

The following is a list of problems



What impressed me today is a database operation question.


Question: There are three tables, which are required to query the eid and ename of all employees who [job development only]



At first, I felt very simple. I wrote the following SQL statement into it.

Select eid, ename from emp where eid not in (select eid from ej where jid = (select jid from job where jname = 'test '));

Later I thought it would be right, but what if there are three or more positions?

For example


The original statement is obviously not applicable.

Then I found another method.

Select eid, ename from emp where eid not in (select eid from ej where jid in (select jid from job where jname <> 'developing '));

The query result is correct! But...

I used two subqueries to reduce the efficiency of SQL statements. Is there a better way?


Here, I also hope to get your suggestions and see if there is a better answer!



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.