How to sort query results according to fields of another table through chain operations in TP5
葫芦娃平衡盘
葫芦娃平衡盘 2018-04-19 16:50:01
0
2
1407

Specific situation: One user table and the other is a user level table. I query (select) the information of the user table and want to sort it according to the power field of the user level table. What I wrote myself is to query the records one by one through a for loop. It feels unscientific to write it into a two-dimensional array. I can check the database as many times as there are pieces of data. Is there a better way to write multi-table queries? Related?

In other words, query the information of people with IDs 3,5,2 and sort them by 3,5,2

葫芦娃平衡盘
葫芦娃平衡盘

reply all(1)
苒苒

Is there a useful framework? If you use the framework, the multi-table related query in it is simpler to write. Now write a native sql statement. Because I don’t understand the second half of your request, I will write it according to the power field sorting of the user level table:

sql = "SELECT u.id,u.name,m.power FROM user table as u INNER JOIN user level table as m ON u.id = m.uid ORDER BY m.power";

What to check specifically The fields are based on their own needs. u.id represents the id in the user table, and m.uid is the user id field attribute stored in the user level table

  • reply Thank you. I didn’t use the framework. I learned it. I didn’t think of using associations before.
    葫芦娃平衡盘 author 2018-04-21 12:15:37
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template