Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2008
    Posts
    99

    Unanswered: unions in sql query

    Hello,

    I have a query which has 2 unions.I d like to remove unions by using one select query
    how can I combine those unions into one query and if I do,will I increase performance of sql

    I can summarize the query as below

    1st select group
    union
    2nd select group
    union
    3rd select group


    These 3 groups have

    Thanks
    Kind Regards
    Last edited by sunsail; 01-30-09 at 08:09.

  2. #2
    Join Date
    Mar 2008
    Posts
    89
    You will want to have a look at subqueries.
    I don't know of any performance differences between the two methods.
    "My brain is just no good at being a relational Database - my relations suck real bad!"

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Without seeing your query it is difficult to show how to re-write it! In some cases an UNION can be re-written, in some it can't.

    This can:
    Code:
    select ename from emp where deptno=10
    union
    select ename from emp where deptno=20
    as
    Code:
    select ename from emp where deptno in (10, 20)
    This can't:
    Code:
    select ename from emp where deptno=10
    union
    select cname from customers where status='NEW'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •