Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,161,449 members, 7,846,878 topics. Date: Saturday, 01 June 2024 at 05:25 AM |
Nairaland Forum / Science/Technology / Programming / Mysql Group By Displaying One Row Instead Of Two (635 Views)
Can You Write Codes With A Tablet Instead Of A Laptop? / Group By Works But Selects Only One Subject_id / Learn PHP & MYSQL The Fast Way. (2) (3) (4)
Mysql Group By Displaying One Row Instead Of Two by goldmines214: 10:41am On Jul 20, 2021 |
I have a broadsheets table with student_id 5 and 6 but when I run the query in the image I get just one row but if I remove the group by I get all 6 rows in the broadsheets table. Please I need assistance
|
Re: Mysql Group By Displaying One Row Instead Of Two by Karleb(m): 12:22pm On Jul 20, 2021 |
Why not just screenshot your laptop? |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 3:45pm On Jul 20, 2021 |
Karleb: Will do that |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 4:28pm On Jul 20, 2021 |
This is the code I have written
|
Re: Mysql Group By Displaying One Row Instead Of Two by stanliwise(m): 5:30pm On Jul 20, 2021 |
goldmines214:Group by is used in conjunction with an aggregation function but with you query I don’t see how group by is helpful. |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 5:55pm On Jul 20, 2021 |
stanliwise: I know that but I also want to select from the students and subjects tables but if I use aggregate functions let's say max(students.fname) then it means that I will be looking for the maximum of students first name instead of all the students names. Please How do I arrange the above query so the group by can be helpful? |
Re: Mysql Group By Displaying One Row Instead Of Two by stanliwise(m): 7:01pm On Jul 20, 2021 |
goldmines214:For group by to work, all column you select must have exactly same content except the aggregator column. Meanwhile in your sql statement you made no use of aggregator so why do want to use group by To put things straight you are not aggregating anything and so you don’t need a groupBy it is as simple as that. |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 10:04pm On Jul 20, 2021 |
stanliwise: What I am trying to achieve is that I have different students offering different subjects with the subjects scores so I was thinking I can group by the student_id and so that I can add all the subjects scores offered by a particular student |
Re: Mysql Group By Displaying One Row Instead Of Two by stanliwise(m): 2:33pm On Jul 21, 2021 |
goldmines214:Then simply do something like select student_id, SUM(subject_score) ...... group by student_id It would be of the above nature, you can add the rest join but don’t add extra column that could make the return two appear different |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 6:51pm On Jul 21, 2021 |
stanliwise: I like this idea but how do I select the other columns like name from students table and subject_name from subjects table then join it to this your query. Please help |
Re: Mysql Group By Displaying One Row Instead Of Two by stanliwise(m): 9:39pm On Jul 21, 2021 |
goldmines214:If you’re trying to get the sum then it has to be separate query. Selecting student. Meta data has to also be a separate query. Meanwhile if you want to add all query in same query forget using grouped by. Now something is even confusing about your query, if you need details about just a student then what do you need groupBy for ? |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 7:20am On Jul 22, 2021 |
stanliwise: The query is not just for a single student. It's for all students in a class. It's a school broadsheet |
Re: Mysql Group By Displaying One Row Instead Of Two by goldmines214: 8:03am On Jul 22, 2021 |
This is a simple query I wrote and it's still showing me one record instead of two. I have two student_id 5 and 6 in my broadsheets table. What must be wrong?
|
(1) (Reply)
Got My First Job Interview / I Need Php Script For My Ecommerce Site / Help Me Review My Startup Idea
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19 |