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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two SELECT statements in one query

Status
Not open for further replies.

jaanisf

Technical User
Apr 30, 2003
50
LV
I need two SELECT statements in one query, because it cannot be done by one statement. Can it be done somehow?

Example:

SELECT Field0, Sum(Field1 * Field2)
FROM Table1
WHERE Field3 <> 'text' AND Field4 >= Forms!Form1!txtbox1 and Field4 <= Forms!Form1!txtbox2

SELECT Field0, Sum(Field1 * (Field2/100))
FROM Table1
WHERE Field3 = 'text' AND Field4 >= Forms!Form1!txtbox1 and Field4 <= Forms!Form1!txtbox2

I need both these two statements showed in one query datasheet view. I need more, I need them both mixed and sorted by those sums.
 
use union or union all if you want dupes

SELECT Field0, Sum(Field1 * Field2)
FROM Table1
WHERE Field3 <> 'text' AND Field4 >= Forms!Form1!txtbox1 and Field4 <= Forms!Form1!txtbox2
UNION SELECT Field0, Sum(Field1 * (Field2/100))
FROM Table1
WHERE Field3 = 'text' AND Field4 >= Forms!Form1!txtbox1 and Field4 <= Forms!Form1!txtbox2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top