Reputation: 636
I want to select rows both from Report and Terminal table to create such a row like this:
+----+-------------------+---------------------+---------+-------+--------+-----+---------+------+
| id | mac_adresi | zaman | fabrika | kumes | makina | kat | sol_sag | adet |
+----+-------------------+---------------------+---------+-------+--------+-----+---------+------+
| 3 | 97-F9-2C-55-19-72 | 2017-11-18 22:43:29 | Çorum2 | Ana2 | 22 | 12 | So2 | 213 |
+----+-------------------+---------------------+---------+-------+--------+-----+---------+------+
Report table;
+----+-------------------+------+---------------------+
| id | mac_adresi | adet | zaman |
+----+-------------------+------+---------------------+
| 3 | 97-F9-2C-55-19-72 | 213 | 2017-11-18 22:43:29 |
+----+-------------------+------+---------------------+
Terminal table;
+----+-------------------+---------+-------+--------+-----+---------+
| id | mac_adresi | fabrika | kumes | makina | kat | sol_sag |
+----+-------------------+---------+-------+--------+-----+---------+
| 86 | 97-F9-2C-55-19-72 | Çorum2 | Ana2 | 22 | 12 | So2 |
+----+-------------------+---------+-------+--------+-----+---------+
In Terminal table, mac_adresi
is a Primary Key,
In Report table, mac_adresi
is a Foreign Key.
I have tried this query but result is not what I want to achieve.
SELECT report.*,terminal.fabrika,terminal.kumes,terminal.makina,terminal.kat,terminal.sol_sag FROM report JOIN terminal ORDER BY id DESC limit 10
How can I do this?
Upvotes: 1
Views: 35
Reputation: 133400
you should set the ON clause for join
SELECT
report.*
,terminal.fabrika
,terminal.kumes
,terminal.makina
,terminal.kat
,terminal.sol_sag
FROM report JOIN terminal on report.mac_adresi = Terminal.mac_adresi
ORDER BY id DESC limit 10
Upvotes: 1