Backstab Posted May 6, 2009 Share Posted May 6, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/157141-query-to-tally-up-the-count/ Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Uh... so why do you want 2 columns if they're going to be the same value anyways? Quote Link to comment https://forums.phpfreaks.com/topic/157141-query-to-tally-up-the-count/#findComment-827975 Share on other sites More sharing options...
Backstab Posted May 6, 2009 Author Share Posted May 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157141-query-to-tally-up-the-count/#findComment-827988 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/157141-query-to-tally-up-the-count/#findComment-827995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.