473,508 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL beginner: How to count search result "categories"

My SQL experience is pretty limited, sorry if this is a
REALLY basic question.

I have a database of bibliographic records. Each record is
of a certain type as recorded in a Type field: books, articles,
dissertations, reviews, etc. When a user searches the database
I'd like to return a overview of results, by type:

Your search retrieved 291 records:

41 articles
2 dissertations
8 reviews

Of course clicking on each group will yield the records of
that particular Type. Ideally I guess I'd like a query generic
enough to handle any number of different Types. That is it
would include obituaries someday if any of those were added
without any changes to the SQL. Barring that, a query that
explicitely included each Type and would be updated whenever
a new Type was added is acceptable.

I've heard about, but never used, SQL keywords like UNION and
GROUP BY and weird things like that. Would this be maybe a
good way to finally learn how to use these SQL features?

I'm working in Access 2000 via ADO. Moving to SQL Server is
a possibility if Access proves inadequate.

Thanks

Oct 1 '06 #1
2 1955
Arvin Portlock wrote:
My SQL experience is pretty limited, sorry if this is a
REALLY basic question.

I have a database of bibliographic records. Each record is
of a certain type as recorded in a Type field: books, articles,
dissertations, reviews, etc. When a user searches the database
I'd like to return a overview of results, by type:

Your search retrieved 291 records:

41 articles
2 dissertations
8 reviews

Of course clicking on each group will yield the records of
that particular Type. Ideally I guess I'd like a query generic
enough to handle any number of different Types. That is it
would include obituaries someday if any of those were added
without any changes to the SQL. Barring that, a query that
explicitely included each Type and would be updated whenever
a new Type was added is acceptable.

I've heard about, but never used, SQL keywords like UNION and
GROUP BY and weird things like that. Would this be maybe a
good way to finally learn how to use these SQL features?

I'm working in Access 2000 via ADO. Moving to SQL Server is
a possibility if Access proves inadequate.

Thanks
Assuming that the "search" is based on other fields (not the TYPE field) then
you need a simple Totals query for the basic starting point.

SELECT [Type], Count(*) As Qty
FROM TableName
WHERE (your filter criteria)
GROUP BY [Type]

Now, the challenge is to use that query with a dynamic ability to apply
different filter criteria based on the users inputs. Do you know how to do
that?

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Oct 1 '06 #2
Rick Brandt wrote:
Arvin Portlock wrote:
I have a database of bibliographic records. Each record is
of a certain type as recorded in a Type field: books, articles,
dissertations, reviews, etc. When a user searches the database
I'd like to return a overview of results, by type:

Your search retrieved 291 records:

41 articles
2 dissertations
8 reviews

Assuming that the "search" is based on other fields (not the TYPE
field) then
you need a simple Totals query for the basic starting point.

SELECT [Type], Count(*) As Qty
FROM TableName
WHERE (your filter criteria)
GROUP BY [Type]

Holy moley, that's incredible. Such a simple query that does
EXACTLY EXACTLY what I want! I've been testing it on a bunch
of different tables. Thanks for the quick reply. I'm going
to look at GROUP BY again. Now with a specific example where
it met my needs I might have a better chance of understanding
it this time.
Now, the challenge is to use that query with a dynamic ability to apply
different filter criteria based on the users inputs. Do you know how
to do
that?

Yes, thanks. That much I can muddle through.

Regards,

Arvin

Oct 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1920
by: Ovid | last post by:
Hi, I've run into a bit of a sticky design issue. We have products in three categories which I will call 'A', 'B' and 'C'. We have "kits" which contain three products, one from each category....
1
2174
by: Yasso Picasso | last post by:
Greetings, I have to admit that I'm still a beginner in the database field, but I'm actively studying, and this is why I will be utterly grateful for the proper, accurate, and wise guidance to...
19
6744
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
6
13578
by: TS | last post by:
Hi, i have a problem validating xml against schema. I used http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx validator and it says it is fine. Can you tell me why this doesn't work? ...
2
3025
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
188
17200
by: infobahn | last post by:
printf("%p\n", (void *)0); /* UB, or not? Please explain your answer. */
1
3138
by: Giorgio | last post by:
Hi, I have a dropdown menu with categories and when a category is selected the Gridview is binded with sub-categories. Then when a sub-category is selected a detailsview is displayed...
6
1993
by: karen987 | last post by:
I have a webpage called "topicview.asp" on a news website with ASP pages, it's a simple news publishing software. You add the news from the Admin section and all the details are stored in a...
1
1581
by: wfsmith | last post by:
Sorry for the confusing subject. Here's what im doing: I have a table of products. Products have N categories and subcategories. Right now its 4. But there could be more down the line so it...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7382
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5052
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.