有两张桌子
表格1
select * from manage_tcp;
+----+----------+--------+
| id | services | statut |
+----+----------+--------+
| 2 | 1433 | up |
| 2 | 3389 | up |
| 3 | 3389 | down |
| 3 | 1433 | down |
| 9 | 3389 | up |
| 8 | 3389 | up |
| 7 | 1433 | up |
| 6 | 3389 | up |
| 5 | 3389 | up |
| 4 | 3389 | up |
| 10 | 1433 | up |
| 11 | 1433 | up |
| 12 | 3389 | up |
| 13 | 1433 | up |
| 14 | 3389 | up |
| 15 | 1433 | up |
| 16 | 3389 | up |
| 17 | 1433 | up |
| 18 | 3389 | up |
| 19 | 1433 | up |
| 20 | 3389 | up |
| 21 | 1433 | up |
| 24 | 1433 | up |
| 23 | 3389 | up |
| 25 | 3389 | up |
| 26 | 1433 | up |
| 29 | 1433 | up |
| 28 | 3389 | up |
| 30 | 3389 | up |
| 31 | 80 | up |
| 32 | 3389 | up |
| 33 | 80 | up |
| 34 | 3389 | up |
| 35 | 80 | up |
+----+----------+--------+
34 rows in set (0.00 sec)
表 2
mysql> select * from manage_host;
+----+------------+-------------+--------+-------+--------------+----------+------+
| id | uptime | type | statut | group | thresold_ref | thresold | mail |
+----+------------+-------------+--------+-------+--------------+----------+------+
| 2 | 277248529 | win2003.png | up | 4 | 1 | 0 | NULL |
| 3 | 277277471 | win2003.png | prob | 4 | 1 | 0 | NULL |
| 4 | 346159833 | win2003.png | up | 4 | 1 | 0 | NULL |
| 5 | 930205491 | win2003.png | up | 5 | 1 | 0 | NULL |
| 6 | 3805663007 | win2003.png | up | 5 | 1 | 0 | NULL |
| 7 | -1 | win2003.png | up | 4 | 1 | 0 | NULL |
| 8 | 29413867 | win2003.png | up | 5 | 1 | 0 | NULL |
| 9 | 981986401 | win2003.png | up | 5 | 1 | 0 | NULL |
| 10 | -1 | win2003.png | up | 5 | 1 | 0 | NULL |
| 11 | -1 | win2003.png | up | 5 | 1 | 0 | NULL |
| 12 | 2230787611 | win2003.png | up | 7 | 1 | 0 | NULL |
| 13 | -1 | win2003.png | up | 7 | 1 | 0 | NULL |
| 14 | 1004161923 | win2003.png | up | 8 | 1 | 0 | NULL |
| 15 | -1 | win2003.png | up | 8 | 1 | 0 | NULL |
| 16 | 1592294954 | win2003.png | up | 8 | 1 | 0 | NULL |
| 17 | -1 | win2003.png | up | 8 | 1 | 0 | NULL |
| 18 | 1449216250 | win2003.png | up | 4 | 1 | 0 | NULL |
| 19 | -1 | win2003.png | up | 4 | 1 | 0 | NULL |
| 20 | 3461945234 | win2003.png | up | 4 | 1 | 0 | NULL |
| 21 | -1 | win2003.png | up | 4 | 1 | 0 | NULL |
| 23 | 3461946968 | win2003.png | up | 4 | 1 | 0 | NULL |
| 24 | -1 | win2003.png | up | 4 | 1 | 0 | NULL |
| 25 | 3462022562 | win2003.png | up | 4 | 1 | 0 | NULL |
| 26 | -1 | win2003.png | up | 4 | 1 | 0 | NULL |
| 35 | 3318333401 | win2003.png | up | 6 | 1 | 0 | |
| 28 | 3461879984 | win2003.png | up | 4 | 1 | 0 | NULL |
| 29 | -1 | win2003.png | up | 4 | 1 | 0 | NULL |
| 30 | 1872950109 | win2003.png | up | 6 | 1 | 0 | NULL |
| 31 | 1872950125 | win2003.png | up | 6 | 1 | 0 | NULL |
| 32 | 1955232033 | win2003.png | up | 6 | 1 | 0 | NULL |
| 34 | 3318333401 | win2003.png | up | 6 | 1 | 0 | |
| 33 | 1955232049 | win2003.png | up | 6 | 1 | 0 | NULL |
+----+------------+-------------+--------+-------+--------------+----------+------+
32 rows in set (0.00 sec)
我想比较上面的这两个表,并在表 1 中得到结果,而不是在表 2 中,例如:(这是我想要的结果)
+----+----------+--------+
| id | services | statut |
+----+----------+--------+
| 2 | 1433 | up |
| 3 | 3389 | down |
| 3 | 1433 | down |
+----+----------+--------+
我试过了
SELECT a.*,b.*
FROM manage_tcp as a
LEFT JOIN manage_host as b
USING(id,statut)
WHERE b.id is null;
但我得到了
+----+----------+--------+
| id | services | statut |
+----+----------+--------+
| 3 | 3389 | down |
| 3 | 1433 | down |
+----+----------+--------+
这不是我想要的。
非常感谢!