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.