SELECT emp_num, years, SUM(salary) FROM sales
UNION ALL
SELECT emp_id, SUM(takehomepay)
FROM marketing

What error is present in the sample code above?

1. Queries being combined with the UNION ALL statement are
not allowed to have SELECT lists with a different number of
expressions.
2. You are not allowed to use aggregate functions within
two queries joined by a UNION ALL statement.
3. The UNION ALL statement incorrectly combines
the "years" result from the first query with the "SUM
(takehomepay)" result from the second query.
4. Unless the UNION ALL statement is replaced with a UNION
statement, the queries will return duplicates.
5. The "emp_id" column from the second query must be
renamed (or aliased) as "emp_num" so that it corresponds to
the column name from the first query. Otherwise, the
queries will not execute.

Answers were Sorted based on User's Feedback



SELECT emp_num, years, SUM(salary) FROM sales UNION ALL SELECT emp_id, SUM(takehomepay) FROM mark..

Answer / menan

Queries being combined with the UNION ALL statement are
not allowed to have SELECT lists with a different number of
expressions.

Is This Answer Correct ?    8 Yes 1 No

SELECT emp_num, years, SUM(salary) FROM sales UNION ALL SELECT emp_id, SUM(takehomepay) FROM mark..

Answer / roopesh kumar

1. Queries being combined with the UNION ALL statement are
not allowed to have SELECT lists with a different number of
expressions.

Reason
Number of columns diff in both query.

Is This Answer Correct ?    7 Yes 1 No

SELECT emp_num, years, SUM(salary) FROM sales UNION ALL SELECT emp_id, SUM(takehomepay) FROM mark..

Answer / tulsi

1)query block has incorrect number of result columns
error displayed will be displayed

2)The group by expressions are missing

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More SQL PLSQL Interview Questions

Is sql considered coding?

0 Answers  


What is a temporal data type?

0 Answers  


What are %type and %rowtype for?

0 Answers  


How to display the records between two range in Oracle SQL Plus?

0 Answers   MCN Solutions,


How will you debug your procedure? If your procedure is around 2000 lines and the expected output is 10 and we get only output 5.So how will you debug it? Somebody pls give the correct answer?

2 Answers   Fidelity,






what is data integrity? : Sql dba

0 Answers  


Can we have two clustered index on a table?

0 Answers  


what is cursor procedure

1 Answers   iGate,


How do I filter in sql profiler?

0 Answers  


TABLE A TABLE B EMPNO ENAME EMPNO ENAME 1 A 1 A 2 B 2 B 3 C 3 C 4 D 4 D 5 E 5 E 6 F 7 G HOW TO GET THE UNMATCHED RECORDS IN SQL QUERY?

10 Answers   Satyam,


what is oltp (online transaction processing)? : Sql dba

0 Answers  


Suppose There is a string A.B....C.......D.........E........F In this string dots (.) are not having fixed count in between of string. I want the output to have string with one dot between. I.e. A.B.C.D.E.F

6 Answers   IBM,


Categories