Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In T-SQL I can accumulate the results of two unioned queries using the following syntax:

SELECT f1 as a, f2 as b FROM TBL1
SELECT f1 as a, f2 as b FROM TBL2

What is the equivalent in Oracle?

share|improve this question

closed as off-topic by Paul White Aug 27 '15 at 17:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Paul White
If this question can be reworded to fit the rules in the help center, please edit the question.

What happened when you tried? – a_horse_with_no_name Apr 2 '13 at 22:25
I get this super-helpful error: ORA-00933: SQL command not properly ended – Daniel Williams Apr 3 '13 at 23:08
up vote 2 down vote accepted

Assuming that you alias the inline view to Q, that syntax should be perfectly valid in Oracle. I'm assuming that you actually have the alias in the SQL Server version as well.

SQL> ed
Wrote file afiedt.buf

  1  select q.a, sum(q.b)
  2    from (select deptno a, sal b from emp
  3          union all
  4          select 40, 10000 from dual
  5         ) q
  6*  group by q.a
SQL> /

         A   SUM(Q.B)
---------- ----------
        30       9406
        20      10880
        40      10000
        10       8753
share|improve this answer
. . Ironically, the posted syntax should work for Oracle (which doesn't require aliases on subqueries), but shouldn't work in SQL Server (which does). – Gordon Linoff Apr 2 '13 at 22:04
Absolutely right, it worked all along. The actual statement was much longer, and in my final Group BY I had a space where a period should have been. But you breaking it down helped. – Daniel Williams Apr 3 '13 at 23:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.