hojjat.mi
hojjat.mi

Reputation: 1534

how to select username from table have multiple userId

User example:

==================
Username   UserId
---------- --------
  A         1
  B         2
===============

and another table like this:

================================================
sendUserId    insertUserId    printUserId  .....
--------------------------------------------
    1             2              1  
================================================

How i can create view to select user info:

sendUserName  insertUserName   printUserName
============================================
   A             B                 A

Upvotes: 1

Views: 381

Answers (1)

Fahmi
Fahmi

Reputation: 37473

You can try below - by joining of multiple instance of user table like below

select u1.Username as sendUserName,u2.Username as insertUserName 
,u3.Username as printUserName
from anothertable
inner join user u1 on sendUserId=u1.userid
inner join user u2 on insertUserId=u2.userid
inner join user u3 on printUserId=u3.userid

Upvotes: 1

Related Questions