| Author |
Topic |
|
IlyaIlya
Starting Member
5 Posts |
Posted - 2009-09-21 : 14:52:44
|
| Hi!There is interesting problem that I cannot solve.Given one table:alias | date-----------------alias1 | 2009-06-08alias1 | 2009-07-23alias2 | 2009-06-05alias2 | 2009-06-09alias3 | 2009-09-23alias3 | 2009-09-21alias3 | 2009-01-21I need to print rows with unique aliases in alphabetic order and then print all other rows in arbitrary order.So, the next rows should be result of the query:alias | data-----------------alias1 | 2009-07-23alias2 | 2009-06-05alias3 | 2009-09-23alias2 | 2009-06-09alias1 | 2009-06-08alias3 | 2009-09-21alias3 | 2009-01-21How can I do that?Thanks a lot. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
IlyaIlya
Starting Member
5 Posts |
Posted - 2009-09-21 : 15:42:02
|
| What are these two queries?As I understood first query is SELECT * FROM `ALIAS` GROUP BY alias;And how can I obtain all other rows? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-09-21 : 17:41:26
|
| try this:select alias, date from <your table> order by rank() over (partition by alias order by date) Be One with the OptimizerTG |
 |
|
|
IlyaIlya
Starting Member
5 Posts |
Posted - 2009-09-22 : 00:13:13
|
quote: Originally posted by X002548 What are "unique" aliases?
Sorry, there were slightly incorrect words. I meant the next: I need to select one row per each alias and it's unimportant what dates would be in these rows.Sorry for my bad English :-) |
 |
|
|
IlyaIlya
Starting Member
5 Posts |
Posted - 2009-09-22 : 00:13:56
|
quote: Originally posted by TG try this:select alias, date from <your table> order by rank() over (partition by alias order by date) Be One with the OptimizerTG
Thank you, I will try |
 |
|
|
IlyaIlya
Starting Member
5 Posts |
Posted - 2009-09-22 : 01:09:53
|
quote: Originally posted by TG try this:select alias, date from <your table> order by rank() over (partition by alias order by date)
Unfortunately, it doesn't work. I use MySQL that doesn't support rank() |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-22 : 03:01:57
|
quote: Originally posted by IlyaIlya
quote: Originally posted by TG try this:select alias, date from <your table> order by rank() over (partition by alias order by date)
Unfortunately, it doesn't work. I use MySQL that doesn't support rank()
This forum is for MS SQL ServerPost your question www.mysql.comMadhivananFailing to plan is Planning to fail |
 |
|
|
|