Jump to content

Recommended Posts

Say I have two tables, assignments and students.

Each have a auto_incement key value.

 

How would make a query which would return a table containing two columns, one with the count of the students, and one with the count of the assignments?

 

students(student_id)

assignent(assignment_id)

 

Say there were 4 students and 5 assigments.

 

select count(student_id), count(assignment_id) from students, assignments

returns a table

count(student_id) | count(assigment_id)
         20      |          20

 

rather than the

count(student_id) | count(assigment_id)
         4      |          5

that I expected.

 

My problem is combining the data into one table with out them multiplying together.

 

 

Server version: 5.0.75-0ubuntu10

Link to comment
https://forums.phpfreaks.com/topic/157141-query-to-tally-up-the-count/
Share on other sites

Uh... so why do you want 2 columns if they're going to be the same value anyways?

 

I want a table which holds the counts of the number of students and the number of assignments.

 

select count(student_id) from students;  = 4

 

select count(assigment_id) from assignments;  = 5

 

I'm need help with a query that makes a table displaying student count and assignment count.

 

the query I posted before isn't right because it multiplies the counts together, rather just displaying them.

 

 

 

It doesn't make sense to have it in 2 columns when you have different number of rows per column in those 2 tables.

 

You can do this:

SELECT COUNT(student_id) FROM students UNION SELECT COUNT(assignment_id) FROM assignments;

That would give you 2 rows. The first is student_id and the second is assignment_id.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.