var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: "order by" doesnt behave the way I need
Hello guys, got a small proble,(I hope it's small)
I need to get my results ordered alphabetically BUT theres a small detail
when some strings in the field I am ordering by contains some white or blank spaces, PSQL does not group them
Here is an example of what I have and what I want to have
create table test(
id int primary key,
The data in my table is:
id | data
1 | John
2 | Julian
3 | Johnny
4 | John Edward
5 | John Joe
6 | Juliette
7 | John Peter
8 | Johnk
9 | John Tracy
10 | Johnd
If I do: "select data from test order by data;"
What I Need and dont know how to do:
As you can see, what I want is to group the John's that have a white space following it before starting to list the John* that follow alphabetically (Johnd, Johnk, Johnny, etc)
order by replace(data, ' ', '0')
it works!!! thanks!!
But I dont understand how it works, I havent figured it out
I got the example from the psql docs:
replace('abcdefabcdef', 'cd', 'XX')
has the result:
so how come I dont have zero's all over where the blank spaces used to be?
Because it's only used for the ORDER BY.
Originally Posted by bitar
In the SELECT list, you still have the original value.
now I get it, thank you shammat