Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine queries 1

Status
Not open for further replies.

abenstex

Programmer
Jan 9, 2005
47
DE
Hi everyone,

instead of executing several queries like
Code:
SELECT a FROM table WHERE id=1
and
Code:
SELECT b FROM table WHERE id=2
I would like to combine the queries. I tried already using subqueries like
Code:
SELECT (SELECT a FROM table WHERE id=1), (SELECT b FROM table WHERE id=2)
but without success. Can anyone give me a hint as to how to combine two or more queries on the same table but with different conditions for each field?
 
Code:
select case when id=1
            then a 
            else NULL  end  as a
     , case when id=2
            then b 
            else NULL  end  as b
  from daTable
 where id in (1,2)



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top