A
A
alex995052017-10-26 10:29:10
SQL
alex99505, 2017-10-26 10:29:10

How to output 2 values ​​with different names of one table connected by join to another?

There is a table user with fields id, name. There is table1. There are two fields in table1 in the same record with different record ids from the user table.
I want to get data from table1 + name of the first user AS name1 and name of the second user AS name2.
Can you please tell me how this can be implemented?
To get one name, do this

SELECT user.name FROM table1 INNER JOIN user ON table1.id1=user.id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2017-10-26
@Austin_Powers

It is possible like this:

SELECT user1.name as user1, user2.name as user2
FROM table1 
INNER JOIN user as user1
  ON table1.id1=user1.id
INNER JOIN user as user2
  ON table1.id2=user2.id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question