Get the data related to more than one table, separately?

-1

I can not do this at all. It seems to be with the join, but when I try, it returns zero records.

I have the tables: TB1, TB2, TB3, TB4, TB ... etc All with PK (ID)

I tried this code:

SELECT ID
FROM TB1
inner join TB2 on (TB1.ID = TB2.ID)
inner join TB3 on (TB1.ID = TB3.ID)
inner join TB4 on (TB1.ID = TB4.ID)

Here it will only display the ID that is common in the four TB's. I want it to show if it pops into any of them.

    
asked by anonymous 27.08.2018 / 15:43

1 answer

0

Table orders (tb_pedidos):

id_pedido (PK) | person_id | descrição   | preço
------------------------------------
1              | 1         | iphone 5    | 100
2              | 1         | iphone 6    | 200
3              | 1         | samsung Tv  | 300
4              | 2         | samsung APT | 110
5              | 3         | Phillips TV | 250
6              | 3         | Phillips ph | 260

Table Apple_Extravio:

id (PK) | id_pedido | description | data
------------------------------------
1       | 1         | Perda       | 24/07/2017
2       | 2         | Roubo       | 08/07/2015

Table Samsung_Extravio:

id (PK) | id_pedido | description | data
------------------------------------
3       | 5         | Indefinido  | 16/06/2014

Table Phillips_Extravio:

id (PK) | id_pedido | description | data
------------------------------------
N       | N         | N           | N

That's basically it. The main order table. And the others are filled when the order has some delivery problem. Every time something happens the php code inserts the information in the other tables, of its respective brand. This only occurs when a problem is reported by the deliverer, and the responsible employee enters the system with that data. The table has been created for years and has more than 200,000 records.

So what am I doing: On another screen, I need to display the logs that had problems. I need to compare the 'order_id' of the main table with those of the loss tables. Whenever the order_id is found in any of the loss tables, it goes to list and is displayed.

The way I'm trying to do, it's not working:

SELECT id_pedido
FROM tb_pedidos as p
INNER JOIN Apple_Extravio ae ON (p.id_pedido = ae.id_pedido)
INNER JOIN Samsung_Extravio se ON (p.id_pedido = se.id_pedido)
INNER JOIN Phillips_Extravio ON (p.id_pedido = pe.id_pedido)

This shows me 0 results.

    
27.08.2018 / 16:48