K
K
Kanat Kharasaev2016-05-26 07:32:52
PHP
Kanat Kharasaev, 2016-05-26 07:32:52

How to make a selection from three tables?

How to make a selection from three tables linked by one table?
I write something like this but it doesn't work

SELECT game.id,npc.title,users.login FROM game INNER JOIN npc ON game.id = npc.npc_id AND game.type = 'npc' INNER JOIN users ON game.id = users.user_id AND game.type = 'user'

Here is an example of tables8ac2141bc02b45e29cae2d9cec856722.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
cheshirerabbit, 2016-05-26
@k_e_m_e_l

SELECT game.id,npc.title,users.login 
FROM game 
LEFT JOIN npc ON game.id = npc.npc_id AND game.type = 'npc' 
LEFT JOIN users ON game.id = users.user_id AND game.type = 'user'
WHERE game.type IN('npc' , 'user')

Александр Путров, 2016-05-26
@Zlobnost

если я правильно понял картинку, то вам нужно использовать UNION

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question