To get the user's name, use leftjoin or cycle through the library.

problem description

in the list of getting articles, if you want to display the name of the user who created the article, do you want to check the user table according to the data obtained by leftjoin or cyclically and then look up the user table according to uid?

Jul.22,2021

Why cycle through the acquired data? (do not execute sql in the loop. Hello)
you can use array_unique (array_column ()) to take out the user id,
of the article table, and then use the in user id to query the corresponding name of the user's id, and then traverse the article table to add the author's name

.

this is also a way. I really haven't tested who is fast and who is slow.
tables will be locked when associating queries, and high concurrency will have a certain performance impact.
however, there is a saying that the number of database operations should be minimized. There are still trade-offs here
anyway, it depends on your specific business situation


left join is much faster than cycling to check the user table according to uid. At present, some lists of items on hand are checked one by one to check the user name, sometimes even for several minutes. After changing to a federated query, the speed is about the same as that of running a sql, basically in seconds

.
Menu