473,394 Members | 1,738 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,394 software developers and data experts.

How to Query more than one Col1 in Col2?

Hi all,

I have a table with two columns called for example instructor and class
one instructor may teach more than one class. How can I query how many classes each instructor teaches?

Let me make up the table.

Instructor Class

Mr. A physics
Mr. A Calculus
Ms.B Cooking for dummy
Ms.B English

Thanks
Nov 16 '07 #1
4 1093
amitpatel66
2,367 Expert 2GB
Hi all,

I have a table with two columns called for example instructor and class
one instructor may teach more than one class. How can I query how many classes each instructor teaches?

Let me make up the table.

Instructor Class

Mr. A physics
Mr. A Calculus
Ms.B Cooking for dummy
Ms.B English

Thanks
HINT: Make use of COUNT(class) and GRUOP BY instructor in the SELECT query

Please POST what you have tried?
Nov 16 '07 #2
HINT: Make use of COUNT(class) and GRUOP BY instructor in the SELECT query

Please POST what you have tried?
Expand|Select|Wrap|Line Numbers
  1. select instructor ,count(instructor) from ThisTable group by  instructor;
I think it will work. My mine was dump yesterday. Thanks.
Nov 16 '07 #3
mwasif
802 Expert 512MB
Well done newbieBrian. This query will work for you. If you also need the classes with the instructer, you can use GROUP_CONCAT() to get a list of comma separated classes.
Nov 16 '07 #4
amitpatel66
2,367 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. select instructor ,count(instructor) from ThisTable group by  instructor;
I think it will work. My mine was dump yesterday. Thanks.
Good work NewbieBrian :)
I appreciate

MODERATOR
Nov 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Debbie Davis | last post by:
Hi there, SQL 2000 I have the following query: SELECT sponsor, COUNT(sponsor) * 2 AS total FROM Referrals GROUP BY sponsor Works great, returns the sponsor and the total * 2 of their...
3
by: Thomas R. Hummel | last post by:
Hi, I was just helping a coworker optimize a query. He had two versions: one which used UNION for each value for which he was tallying results and another query which used GROUP BY. Here is an...
22
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20...
2
by: Muzamil | last post by:
Table: All columns int -------- Col1 Col2 Col3 1 1 4 1 2 4 1 3 7 2 1 8 2 2 8 2 4 8
6
by: DC Gringo | last post by:
I have a series of select queries that use the nesting method but are creating such a huge query that the server can't handle it. The IN section in some cases are so large that I can't even...
3
by: Omavlana | last post by:
Hi, How to get the value as 0 insted of NULL if there is no data found in the database for a particular column in the following Access query. select col1, col2 from tab1; If there are null...
0
by: Stephen | last post by:
Hi, Suppose I have 2 tables. TableA has about 3 million rows and TableB has about 50,000 rows. Assuming a btree index is used in the time column. I need to query a limited and time ordered...
3
by: msrviking | last post by:
Hello everybody, After several attempts of writing the query, I had to post my requirement in the forum. Here is what I have, what I need and what I did. Table A Col1 Col2 1 Nm1
3
by: shorti | last post by:
db2 v 8.2 on AIX 5.3 I will try to explain as brief as I can what it is I need. I am building a function that will be called multiple times where I will need to return x amount of records each...
4
by: resmi318 | last post by:
I am running a query similar to given below. CREATE TABLE ABC_08 AS (SELECT x.col1, trim(x.col2), x.col3, x.col4, x.col5 FROM Table1 x
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.