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

Explain mutating table error.

0 Answers  


What sql does db2 use?

0 Answers  


How to call DDL statements from pl/sql?

5 Answers  


Can a key be both primary and foreign?

0 Answers  


what is 'mysqlshow'? : Sql dba

0 Answers  






Mention what does the hierarchical profiler does?

0 Answers  


How is use pl and sql?

0 Answers  


What are few of the schema objects that are created using PL/SQL?

0 Answers  


What does sql stand for?

0 Answers  


I have one Excel file with 1,50,000 Records. Now I need to load that whole file into Oracle Database with same columns in Excel sheet . I need PLSQL Procedure or used by SQL PLUS

7 Answers   Polaris,


Can you create a table with Primary Key not as the clustered index.

2 Answers   CGI,


how many columns can be used for creating index? : Sql dba

0 Answers  


Categories