Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with sorting

Author  Topic 

ZkInPhamouS
Starting Member

5 Posts

Posted - 2012-03-12 : 14:12:12
Hi all,

I'm trying to sort a column and group it in certain way.. basically, this is my situation.

I ORDERED BY column B in an ASC order, however, within that column I also need to group say... "all the X001" together and "all the Y012" together.

Right now the format is like...

Column B
The High Impact Axe X001
The High Impact Drill Y012
The High Impact Hammer X001
The Low Impact Axe X001
The Low Impact Drill Y012

you see, the names are in ASC order, but at the same time, I also need to group all the X001s and Y012 together.

Any suggestions?

Thanks!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-12 : 14:37:09
order by right(ColumnB,4),ColumnB


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ZkInPhamouS
Starting Member

5 Posts

Posted - 2012-03-12 : 14:45:15
Thanks!

but I forgot to mention that at the end, it isn't so predictable, it's more like
X001 - xsuagejake
Y012 -iryhanldjiljaj
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-12 : 15:11:35
quote:
Originally posted by ZkInPhamouS

Thanks!

but I forgot to mention that at the end, it isn't so predictable, it's more like
X001 - xsuagejake
Y012 -iryhanldjiljaj


so you need to consider whole of it or just the X001,Y012 part alone? also will the format be always consistent?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ZkInPhamouS
Starting Member

5 Posts

Posted - 2012-03-12 : 15:21:56
quote:
Originally posted by visakh16

quote:
Originally posted by ZkInPhamouS

Thanks!

but I forgot to mention that at the end, it isn't so predictable, it's more like
X001 - xsuagejake
Y012 -iryhanldjiljaj


so you need to consider whole of it or just the X001,Y012 part alone? also will the format be always consistent?



Just X001 and Y012 part alone, but the format is not always consistent.
It will be like:

Column: Data Test
abcd: X001 - qwertyyu
xyz:X001 - asdfghjkl
bnmas: Y012 - zxdfvghn
xbsjew :X001 - rhjshjkf
akdj: Y012 - jfsdklfjksdjfksdjf

so far, I have the name in alphabet order, but I also need to order/group X001 & Y012 together.

I tried substring, but it didn't work because it's inconsistent.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-12 : 16:44:57
will there be - always as a separator?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ZkInPhamouS
Starting Member

5 Posts

Posted - 2012-03-13 : 07:52:05
quote:
Originally posted by visakh16

will there be - always as a separator?



Yeah, but I figured it out, by using substring_index, I could potentially narrow it down to what what I need, which is the middle section, the "X001" or "Y012"

Thanks all!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 07:54:47
So you are using MySQL?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ZkInPhamouS
Starting Member

5 Posts

Posted - 2012-03-13 : 08:02:33
quote:
Originally posted by webfred

So you are using MySQL?


No, you're never too old to Yak'n'Roll if you're too young to die.



Now that you pointed out, I want to apologize, yeah, it's MySQL, I just recently started learning it.

I realized that I'm on the wrong forum after you mentioned it and I did a search for MySQL forum.

Again, I apologize for all the trouble.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-13 : 08:12:22
No problem since you were able to solve your problem by yourself (in order to answer on visakh's questions which brought you on the right track).


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -