[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

Group by - 2

I have this table
Id    AId   BId  
1     1       1
2     1       1
3     1       2
4     1       2
5     2       1
6     2       2
From this table I would like to group by 1) AId   2) BId
So that I would get returned:
AId    BId
1        1
1         2
2         1
2         2
How can I do this?    
0
johnkainn
Asked:
johnkainn
4 Solutions
 
pcelbaCommented:
SELECT AId, BId
  FROM YourTable
  GROUP BY AId, BId
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
select distinct AId ,  BId from tableName

SELECT AID, bID from tableName GROUP BY AId ,  BId
0
 
sarabhaiCommented:
take the decision on which column you should group.

SELECT AID, bID FROM T_group
GROUP BY AId ,  BId
0
 
DBAduck - Ben MillerPrincipal ConsultantCommented:
All the above will work.  Just so it is stated in this question, if you do not specify an aggregate in the SELECT (like SUM, AVG, COUNT, etc) then the GROUP BY will do a DISTINCT.  Which is the same as just saying SELECT DISTINCT with the columns you want to have in the output.

This is what aneeshattingal stated.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now