D
D
Denis2017-06-21 18:02:13
PHP
Denis, 2017-06-21 18:02:13

How to write a SQL query to filter on three tables?

In general there are 2 tables
1 - `servers` (server_id, server_name );
2 - `server_mod` (m_serv, m_mod );
1. there is a table of servers with the name of the server
2. There is a table where only the mod id and the server id (from the first two tables)
Help me make a search query , for example, I need to show all servers that have mod. id = 5 I
tried on JOIN, but it didn't work,
thank you very much for your answers .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan Polin, 2017-06-21
@Virtus_pro

It can be like this:

SELECT s.server_name FROM mod_name m LEFT OUTER JOIN(
    SELECT m_mod, m_serv FROM server_mod
) q ON q.m_mod = mod_id 
LEFT OUTER JOIN(
    SELECT server_id, server_name FROM servers
) s ON s.server_id = q.m_serv WHERE mod_id = 5

sql fiddle

O
Oleg, 2017-06-21
@Austin_Powers

Use JOIN. Instruction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question