Click here to Skip to main content
13,506,611 members
Rate this:
Please Sign up or sign in to vote.
See more:
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 24-Apr-17 9:47am
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
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
Member 13143008 24-Apr-17 22:55pm
But i cant get the name plz give me a solution
Maciej Los 25-Apr-17 17:03pm
Have you, tried my solution? Seems, you don't, because the second column in select statement is the name of the group.
Member 13143008 25-Apr-17 23:20pm
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 26-Apr-17 12:12pm
You should post it as another question. Let me know when you finish. I'll try to help you.
Member 13143008 28-Apr-17 3:04am
ok sir thank 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 |
Web03 | 2.8.180417.1 | Last Updated 24 Apr 2017
Copyright © CodeProject, 1999-2018
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