我想从报告和终端表中选择行来创建如下所示的行:
+----+-------------------+---------------------+---------+-------+--------+-----+---------+------+
| 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 |
+----+-------------------+---------------------+---------+-------+--------+-----+---------+------+
报告表格;
+----+-------------------+------+---------------------+
| id | mac_adresi | adet | zaman |
+----+-------------------+------+---------------------+
| 3 | 97-F9-2C-55-19-72 | 213 | 2017-11-18 22:43:29 |
+----+-------------------+------+---------------------+
终端表;
+----+-------------------+---------+-------+--------+-----+---------+
| id | mac_adresi | fabrika | kumes | makina | kat | sol_sag |
+----+-------------------+---------+-------+--------+-----+---------+
| 86 | 97-F9-2C-55-19-72 | Çorum2 | Ana2 | 22 | 12 | So2 |
+----+-------------------+---------+-------+--------+-----+---------+
在终端表中,mac_adresi
是主键,
在报告表格中,mac_adresi
是外键。
我尝试了这个查询,但结果不是我想要达到的目的。
SELECT report.*,terminal.fabrika,terminal.kumes,terminal.makina,terminal.kat,terminal.sol_sag FROM report JOIN terminal ORDER BY id DESC limit 10
我该怎么做?
答案 0 :(得分:1)
你应该为join
设置ON子句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