MySQL Forums
Forum List  »  InnoDB

Sort (ORDER BY) by a comma-separated list of related fields using MySQL 4.1?
Posted by: Phil Powell
Date: February 04, 2006 06:30PM

Quote

create table table_a (
id int not null,
primary key (id),
a_name varchar(125) not null
);

create table table_b (
id int not null,
primary key (id),
b_name varchar(75) not null
);

create table a_b_assoc (
a_id int not null,
b_id int not null,
primary key (a, b)
);

Ok, you have three tables. You're supposed to be able to not only sort (ORDER BY) according to a_name, no problem, but you must also have the ability to sort (ORDER BY) the relationship between table_a and table_b, that is, say you have this:

Quote

insert into table_a (a_name) values ('Phil');

insert into table_b (b_name) values ('programmer');
insert into table_b (b_name) values ('developer');
insert into table_c (c_name) values ('emperor of the known universe');

insert into a_b_assoc (a_id, b_id) values ('1', '1');
insert into a_b_assoc(a_id, b_id) values ('1', '2');
insert into a_b_assoc(a_id, b_id) values ('1', '3');

Here is where the problem lies. I am required to be able to sort by 'Phil', no problem:

Quote

ORDER BY upper(a_name) ASC

But how on earth do I sort THIS way:

Quote

--PSEUDO CODE, of course
ORDER BY upper('programmer, developer, emperor of the known universe') ASC

in other words, how do I sort a resultset query where each a_name will have multiple b_name field values BY their adjoined b_name field values comma-separated?

I'm sorry if that made no sense but that's as clear as I'm able to make it.

Phil

Options: ReplyQuote


Subject
Views
Written By
Posted
Sort (ORDER BY) by a comma-separated list of related fields using MySQL 4.1?
10876
February 04, 2006 06:30PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.