Interview Question


Country: India




Comment hidden because of low score. Click to expand.
4
of 4 vote

SELECT empno, sal
FROM emp
WHERE sal > ANY (2000, 3000, 4000);

EMPNO SAL
---------- ----------
7566 2975
7698 2850
7782 2450
7788 3000
7839 5000
7902 3000

SQL>

-- Transformed to equivalent statement without ANY.

SELECT empno, sal
FROM emp
WHERE sal > 2000 OR sal > 3000 OR sal > 4000;

EMPNO SAL
---------- ----------
7566 2975
7698 2850
7782 2450
7788 3000
7839 5000
7902 3000

- Anonymous July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 4 vote

SELECT empno, sal
FROM emp
WHERE sal > ALL (2000, 3000, 4000);

EMPNO SAL
---------- ----------
7839 5000

SQL>

-- Transformed to equivalent statement without ALL.

SELECT empno, sal
FROM emp
WHERE sal > 2000 AND sal > 3000 AND sal > 4000;

EMPNO SAL
---------- ----------
7839 5000

SQL>

- Anonymous July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

SELECT *

FROM EMPLOYEES

WHERE SALARY IN (1500, 3000, 2500)


In the query above, Oracle would select only those records where the salary is equal to either 1500, or 3000, or 2500.

- Anonymous July 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

ANY (or its synonym SOME) is a syntax sugar for EXISTS with a simple correlation:

SELECT *
FROM mytable
WHERE x <= ANY
(
SELECT y
FROM othertable
)

is the same as:

SELECT *
FROM mytable m
WHERE EXISTS
(
SELECT NULL
FROM othertable o
WHERE m.x <= o.y
)

With the equality condition on a not-nullable field, it becomes similar to IN.

All major databases, including SQL Server, MySQL and PostgreSQL, support this keyword.

Source: stackOverFlow

- ha July 23, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More