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!

Select but do not display or Group 1

Status
Not open for further replies.

briesen

Technical User
May 13, 2008
24
US
I'm pretty green to SQL queries as I come from Crystal Reports. Is it possible to select several different fields and use the WHERE statement to filter some fields, but not display the filtered fields?

Here's an example of what I'm attempting to do, but it tells me I must either group the selected fields or do an aggregate.

SELECT vtr.name, vtr.date, COUNT(vtr.ordernumber) as vcount, vtr.color, vtr.size
FROM ice cream
WHERE vtr.color=green.AND vtr.size=medium
GROUP by vtr.name, vtr.date
 
You don't have to display what is in your where clause. Simply leave it out of your select clause if you don't want to display it.

However, if you are aggregating one or more columns, then you have to group by displayed columns which are not aggregated. So in your example, you would need the following:

Code:
SELECT vtr.name, vtr.date, COUNT(vtr.ordernumber) as vcount, vtr.color, vtr.size
 FROM   ice cream
 WHERE  vtr.color=green.AND vtr.size=medium
GROUP by vtr.name, vtr.date, vtr.color, vtr.size
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top