Click here to Skip to main content
12,892,469 members (45,925 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: MySQL
i have 2 tables.
Group and customer.
Group                            Customer
group_Id  Name                  customer_Id    CusName   groupId
1        sri lanka                  1           Anne      1
2        india                      2           John      2
3        japan                      3           Mark      1


i want to group this tables according to the groupId and i want to display the name according to the groupId in the top of the each groupId in a report

What I have tried:

SELECT Customer.CustomerID,Customer.CusName ,Customer.CreditAllowed,CusGroup.groupId FROM Customer
								INNER JOIN CusGroup on Customer.GroupID=CusGroup.groupId 
								GROUP BY Customer.CustomerID,CusGroup.groupId 
								ORDER BY CusGroup.groupId





i try this but i dont know to display the name
Posted 21-Apr-17 1:08am
Updated 3 days ago
v2
Comments
CHill60 21-Apr-17 9:28am
   
You're not using any aggregate functions (e.g. count, avg, sum,...) so why are you using GROUP BY?
Show your expected results for the data you have shown

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Check this:
SELECT Cg.groupId, Cg.Name, Cu.CustomerID, Cu.CusName, Cu.CreditAllowed
FROM Customer Cu INNER JOIN CusGroup Cg on Cu.GroupID=Cg.groupId 
ORDER BY Cg.groupId, Cu.CustomerID
  Permalink  
Comments
Member 13143008 2 days ago
   
But i cant get the name plz give me a solution
Maciej Los 2 days ago
   
Have you, tried my solution? Seems, you don't, because the second column in select statement is the name of the group.
Member 13143008 yesterday
   
im really sorry sir its my mistake i seems the group name like custmer name. because both names a same sorry for that ur code is working and really thank you for it. and i have another problem can you help me for that plz.


i have table named Customer.
and it has CustomerId , CusName, GroupID, CreditAllowed
1 fernando 1 10
2 perera 2 5
3 anne 1 4
4 mark 2 10
5 john 2 4

i want to group by this according to GroupID and i want to get sub total and grand total of creditAllowed column according to GroupID
Maciej Los yesterday
   
You should post it as another question. Let me know when you finish. I'll try to help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 24 Apr 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100