Combine Two SQL Queries With Separate Where Statements

I have two SQL queries that I would like to combine. Each query is dependent on the same table, and the same rows, but they each have their own WHERE statements. I've thought about using some JOIN statements (left outer join in particular) but then I run
into the problem of not having two separate tables, and don't see where I can put in two separate WHERE statements into the final query. I've read into aliasing tables, but I'm not quite sure how that works (how to put it into code or a JOIN statement) , or
if it would solve my question. Do you have any ideas or examples of how to solve this scenario?

...when you use UNION, each WHERE statement must return an equal number of columns. As in the above example, where each "unioned" WHERE returns two columns of data. The return set will appear as one table, so you may need to name your columns accordingly...

Re: Combine Two SQL Queries With Separate Where Statements

Gaucho

...when you use UNION, each WHERE statement must return an equal number of columns

This poses a problem, I have three columns being returned by one query and two by the other. Is there a way to do this? Also I am wondering if there is a way to sum a column from the frist query with a column of the second query in the union? Also if
possible I would like to avoid doing five subqueries, it seems very inefficient.

Re: Combine Two SQL Queries With Separate Where Statements

When I've run into this, I do something like add a third column to my additional WHERE statement to allow the UNION operator to do it's job. It's not exactly elegant, but it works. As far as using the SUM aggregator to total up two columns as you refer
to, you start getting into GROUP BY clauses which are going to conflict with your UNION operator. You might want to explore combining these statements using some type of subquery.

Re: Combine Two SQL Queries With Separate Where Statements

You could use a user defined function on the server. User defined functions can return a 'table' and can be used in an sql statement just like a table. This should allow you to do a sum in your function and then in your calling sql use a union.

or

You could use two separate Gridviews one directly below the other one and without a header.