我有三個表共享公用列id
。 (但還沒有被設置爲foreign key
)檢索與JOIN共享公共字段的MySQL記錄
+----------------+ +----------------+ +----------------+
| Table 1 | | Table 2 | | Table 3 |
+----+-----+-----+ +----+-----+-----+ +----+-----+-----+
| id | x | y | | id | a | b | | id | c | d |
+----+-----+-----+ +----+-----+-----+ +----+-----+-----+
| 1 | 0.0 | 0.0 | | 1 | 2.0 | 6.0 | | 1 | 0.1 | 0.5 |
+----+-----+-----+ +----+-----+-----+ +----+-----+-----+
| 2 | 0.0 | 0.0 | | 2 | 3.0 | 7.0 | | 2 | 0.2 | 0.6 |
+----+-----+-----+ +----+-----+-----+ +----+-----+-----+
| 3 | 1.0 | 1.0 | | 3 | 4.0 | 8.0 | | 3 | 0.3 | 0.7 |
+----+-----+-----+ +----+-----+-----+ +----+-----+-----+
| 4 | 0.0 | 0.0 | | 4 | 5.0 | 9.0 | | 4 | 0.4 | 0.8 |
+----+-----+-----+ +----+-----+-----+ +----+-----+-----+
在這種情況下,我怎麼能得到包含字段id, x, y, a, b, c, d
其中x = 0.0 and y = 0.0
我希望得到的結果記錄:
+----+-----+-----+-----+-----+-----+-----+
| id | x | y | a | b | c | d |
+----+-----+-----+-----+-----+-----+-----+
| 1 | 0.0 | 0.0 | 2.0 | 6.0 | 0.1 | 0.5 |
+----+-----+-----+-----+-----+-----+-----+
| 2 | 0.0 | 0.0 | 3.0 | 7.0 | 0.2 | 0.6 |
+----+-----+-----+-----+-----+-----+-----+
| 4 | 0.0 | 0.0 | 5.0 | 9.0 | 0.4 | 0.8 |
+----+-----+-----+-----+-----+-----+-----+
我已經以關鍵字join
搜索,但作爲新手,我有點困惑。請問這個查詢:
SELECT * FROM Table1
INNER JOIN Table2
ON Table1.id = Table2.id
INNER JOIN Table3
ON Table1.id = Table3.id
WHERE x = 0.0 and y = 0.0
做我想要的東西嗎?我沒有看到一種select * from Table2
或select * from Table3
的東西。