Problems related to SQL

In

development, when you want to write a query sql, you encounter such a problem: in the
project, there is a user table that stores users with different identities, and a similar field is probably uid (user id), name (user name), identity (user identity). There is another table external query this table, according to different identities to obtain different user information, how to achieve this situation in a sql statement?

< hr >

here"s the thing. There is a table that stores fields similar to id,uid1,uid2, and both uid1 and uid2 correspond to the uid, of the first table. The uid, wants to find a result like id,uid1.name,uid2.name in a query

.
Apr.01,2021

use the left connection according to the field identity
select t1.identity from T1 T1 left join T2 T2 on t1.identity = t2.identity


just associate the user table several times, for example:

select t.*, u1.name, u2.name
from t inner join t_user u1 on u1.uid = t.uid1
       inner jion t_user u2 on u2.uid = t.uid2
Menu