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

How would I write this query?

Status
Not open for further replies.

dj982020

Programmer
Jun 11, 2004
27
US
I want to create a query that allows me to select multiple fields with multiple criteria. For example (pseudo-SQL):


SELECT Field1 WHERE ID=6, Field2 WHERE ID=8, Field3 WHERE ID=11

I know this may not make much sense to do, but I need to find out how to do it.

Please Help!!

~D
 

Not exactly sure what you need, do either of these help?

Option 1
Code:
SELECT Field1, NULL AS Field2, NULL AS Field3 FROM MyTable WHERE ID=6
UNION ALL
SELECT NULL AS Field1, Field2, NULL AS Field3 FROM MyTable WHERE ID=8
UNION ALL
SELECT NULL AS Field1, NULL AS Field2, Field3 FROM MyTable WHERE ID=11
Option 2
Code:
SELECT Field1 AS MyField FROM MyTable WHERE ID=6
UNION ALL
SELECT Field2 AS MyField FROM MyTable WHERE ID=8
UNION ALL
SELECT Field3 AS MyField FROM MyTable WHERE ID=11
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top