sorting - MySQL sort line2 after line1 IF line2.id2=line1.id -


i have 2 little problem sorting tables in mysql querying 1 or more tables, don't doubt subqueries can me, don't know theses types of queries , second example doesn't work expected first.

first, consider table messages , table user, have id table message

table messages

id id2 userid1 userid2 message senddate readdate

id=unique id2:self referencing table message avoid compute dates fields userid1:a message user userid2:a message user ...

so can retrieve messages userid1=userid , userid2=userid using order greatest function on userid1 , userid2, messages ll sorted user sent , received messages same user, column id ll automatically sorted in case of doubt.

the main problem when want same don't figure how table comments , table posts.

i want retrieve comments post, have filter post , take comments how sort comments that:

table comments

id id2 comment userid

how sure ll comments id2=id of previous line?

edit: oops maybe simpler --->> order coalesce(comments.id2,comments.id) make referenced line id2=id1 below themselve ll not works if add com incremented id , id2=0 that: [enter image description here][1]

that's not if decide replace 0 null got :

enter image description here

the problem first null not first line followed others :(

ithink use same number .... have :(

enter image description here

i think have found .... have use same number 0 indentation of comment , use order id2,id


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -