473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to get the number of each unique items?

Hello.
I'd like to know the SQL query for the following operation.
Table
AUTHOR BOOK
Bill A
Bill B
Charles A
Bill C
....

Output
Bill : 3 books
Charles : 1 book

I know that there is a function to get the number of matching field but
in this case I don't know what authors are in this table. Maybe I
should,
1)Get each unique authors
2)Query the number of matching items using author's name.

I don't know how to do the 1 and is there any better way? Thank you.

Oct 29 '05 #1
2 1546
ty*******@gmail.com wrote:
Hello.
I'd like to know the SQL query for the following operation.
Table
AUTHOR BOOK
Bill A
Bill B
Charles A
Bill C
....

Output
Bill : 3 books
Charles : 1 book


select AUTHOR,count(*) as books from yourtablename group by AUTHOR;
Oct 29 '05 #2
ty*******@gmail.com wrote:
1)Get each unique authors
2)Query the number of matching items using author's name.

I don't know how to do the 1 and is there any better way? Thank you.


That is a very, very wrong and slow way to use database. If you need to
use loop in your program to make several queries, you are going to have
very poor performance and usually the same thing can be done with one
quick query. ( Sometimes it is faster to make multiple queries, instead
of one, but you really should know what you are doing if you do that.
And when that is the case, the database is most likely very complex and
queries need to interact with several different tables. )

I already told you how to do this with single query, but if you need to
get unique authors you could:
select AUTHOR from yourtablename group by AUTHOR;
Oct 29 '05 #3

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

Similar topics

8
by: Joe Wong | last post by:
Hi, I need to implement a unique number generator that 1 or more processes on same or different machines will make use of it. Is there any library / project available already for this? Thanks...
1
by: sarah | last post by:
Hi.. I'm having a problem trying to figure out the best way to process a POST and add items to my database, and hope someone can help me... :) Background: I have a database that I will use to...
3
by: Alex | last post by:
Acc 97 Hi, I am in need of some help here.... I have a query which is based upon time, where i need to plot the hours a job has been working.. therefore, oN & off in a union query. ...
1
by: Crimsonwingz | last post by:
I am setting up a database to track incoming shipments by Lot. In one shipment (lot) there will be several items that need to be associated to that lot, but need a unique number to reship by. ...
20
by: William Stacey [MVP] | last post by:
int list = {1,2,3,4,5,6}; Function to randomize the list? Cheers! -- William Stacey, MVP
8
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But...
8
by: Anil Gupte | last post by:
I had someone write a random number generator in C# (I am more of a VB programmer) and they came up with the following: public string GetRand(int count) { string number = ""; for (int i=0;...
2
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.