First I created the two tables and entered the data as it was posted in the question ( Remember to post in the next few questions, it makes it easier for anyone to help you):
CREATE TABLE 'tb_pedido' (
'COD_EMPRESA' int(11) DEFAULT NULL,
'COD_FORNECEDOR' int(11) DEFAULT NULL,
'DATA_EMISSAO' timestamp DEFAULT CURRENT_TIMESTAMP,
'VALOR_PEDIDO' decimal(15,3)
) ENGINE=InnoDb;
INSERT INTO 'tb_pedido' VALUES
(1, 1, '2018-11-01', 1000),
(2, 2, '2018-11-02', 2000);
CREATE TABLE 'tb_pagamento'(
'COD_EMPRESA' int(11) DEFAULT NULL,
'COD_FORNECEDOR' int(11) DEFAULT NULL,
'DATA_ENTRADA' timestamp DEFAULT CURRENT_TIMESTAMP,
'DATA_PAGAMENTO' timestamp DEFAULT CURRENT_TIMESTAMP,
'VALOR_PAGAMENTO' decimal(15,3)
) ENGINE=InnoDb;
INSERT INTO 'tb_pagamento' VALUES
(1, 1, '2018-11-26', '2018-11-27', 1000),
(2, 2, '2018-11-26', '2018-11-28', 2000);
I need a report that shows the data from the tb_pedido and the tb_payment, all in a single table as in example 3
Solution :
SELECT
tped.'COD_EMPRESA', tped.'COD_FORNECEDOR', tped.'DATA_EMISSAO', tped.'VALOR_PEDIDO', tpag.'DATA_PAGAMENTO', tpag.'VALOR_PAGAMENTO'
FROM 'tb_pedido' AS 'tped'
JOIN 'tb_pagamento' AS 'tpag'
ON(tped.'COD_EMPRESA' = tpag.'COD_EMPRESA' AND tped.'COD_FORNECEDOR' = tpag.'COD_FORNECEDOR');
Output As in example 3 ):
+-------------+----------------+---------------------+--------------+---------------------+-----------------+
| COD_EMPRESA | COD_FORNECEDOR | DATA_EMISSAO | VALOR_PEDIDO | DATA_PAGAMENTO | VALOR_PAGAMENTO |
+-------------+----------------+---------------------+--------------+---------------------+-----------------+
| 1 | 1 | 2018-11-01 00:00:00 | 1000.000 | 2018-11-27 00:00:00 | 1000.000 |
| 2 | 2 | 2018-11-02 00:00:00 | 2000.000 | 2018-11-28 00:00:00 | 2000.000 |
+-------------+----------------+---------------------+--------------+---------------------+-----------------+
2 rows in set (0.00 sec)
This is a simple query that should be implemented according to your application.
Remembering : Foreign keys ensure the integrity of the stored data (One of the pillars of MySQL). Using this way, you can delete data from a table that would be associated with another table ... Still not a good practice, it is not the purpose of the question "correct" your database, but rather reproduce a query associating the tables independent of the existence of foreign keys.
Watch this playlist and understand everything: Video Course - MySQL Databases