Sort with a virtual column

I’ve created a fake table called tbl_my_father_is_not_the_neighbor:

create table tbl_my_father_is_not_the_neighbor( 

   id int(5) not null primary key auto_increment, 

   name varchar(100), 

   fatherId int(5), 

   constraint fk_fkfkfk foreign key(fatherId) references tbl_my_father_is_not_the_neighbor(id)

) Engine=InnoDB;

Now a need to create what I’m calling of “virtual column” named “fatherName” that will contain "My father’s name is " + {name of the father} or “I don’t know who’s my father” if the column fatherId is null.

The first thing is: what is the best way of make this "virtual column"?

The second thing is: Once this "virtual column" exists, I need to order my active record by "fatherName" column, for example at admin page of CRUD. Is that possible?


Is there any problem with the question?

Is it very easy?

Is it very hard? :)

Is my question clear?

To make thing easy just paste your code so that one could easyly have a look at it.

It’s possible but u will need to do in memory sorting which is gonna be dog slow if you have many records in a table as u can’t use indexes, so best to avoid it. U would be better maintaining an extra column on the table for performance reasons and index it. Sure u have more data, but better performance. Trying to query or sort on virtual columns is a baaad idea in large tables