Obsidian | Level 7

## Why numbers are not getting grouped?

Writing the above code, I expected the result to be grouped by my first variable name i.e bankid. But it's grouping on Marital status which is 2nd variable. Plz explain why its not getting grouped by bankid though it's written as 1st variable in group by!

1 ACCEPTED SOLUTION

Accepted Solutions
Diamond | Level 26

## Re: Why numbers are not getting grouped?

Your ORDER BY statement groups the data by descending COUNT, that's what is happening. That's the order of the output data. If you want some other order, you need a different ORDER BY statement. The GROUP BY statement does not determine the order of the output data.

--
Paige Miller
4 REPLIES 4
Diamond | Level 26

## Re: Why numbers are not getting grouped?

Maybe you want a different ORDER BY statement?

--
Paige Miller
Obsidian | Level 7

## Re: Why numbers are not getting grouped?

The code and the result generated in correct, it gives exact ans while solving MCQ's but I didn't understand the logic that even after writing bankid first in the GROUP BY statement, the table is getting grouped by marital status first and then within the marital status the bankid is getting grouped.

I was assuming the marital status to be grouped within the bankid.

There is my confusion.

Diamond | Level 26

## Re: Why numbers are not getting grouped?

Your ORDER BY statement groups the data by descending COUNT, that's what is happening. That's the order of the output data. If you want some other order, you need a different ORDER BY statement. The GROUP BY statement does not determine the order of the output data.

--
Paige Miller
Obsidian | Level 7

## Re: Why numbers are not getting grouped?

Great its solved now. Thanks for explaining.
Discussion stats
• 4 replies
• 385 views
• 1 like
• 2 in conversation