Home > database >  How great god ask mysql with a query multiple a one-to-many relationship
How great god ask mysql with a query multiple a one-to-many relationship

Time:09-23

(assuming I only find a one-to-many query)
Suppose I have the user list, post table, the comment form... Table,
These post, comment,... Tables are belong to the user a one-to-many relationship, a user corresponding to multiple post, multiple conment... ,
I use leftjoin link these tables, it found that this order will lead to the back of the table according to the result of the previous leftjoin again the results, the result is the product of all, the
I hope to get the following this:


(the end of the u1, is the largest number of comment, the other column is null because no more)
As above, I hope the back of the table and the user always table lefjoin leftjoin rather than in front of and results,
And post, comment, and later,,, no corresponding relation, according to their order,
Can actually as more user left join multi-table query transverse patchwork, but I don't know how to spell, if separate query, a layer of fine because there would be a few more, one thousand to add a layer of one-to-many is finished,
  • Related