我有以下问题。我有 2 个表想要加入“TableALong”和“TableBLong”
TableALong
ID, Name, Store,Age
1, John, Walmart, 5
2, Johnny, Walmart, 8
3, Johnny, Target , 10
4, Bill, Shoppers, 2
5, Joe, Target, 3
TableBLong
ID, Name, Store, StoreAddress
1, John, Walmart, 35353 Address
1, John, Walmart, 53544 Address
2, Johnny, Walmart, 35353 Address
Run Code Online (Sandbox Code Playgroud)
在加入之前,我想做一些类似 ALIAS 的事情,我有这样的事情:
SELECT A.ID, A.NAME, A.STORE, A.AGE, B.STOREADDRESS
FROM TableALong as A, TableBLong as B
ON A.NAME = B.NAME and A.STORE = B.STORE
Run Code Online (Sandbox Code Playgroud)
这在oracle中是无效的。让它在 oracle 中运行的正确查询是什么?我认为这是我想要的左连接?(连接后,TableALong 中的每一项都会有多行。)
固定查询:
SELECT A.ID,
A.NAME,
A.STORE,
B.STOREADDRESS as yourAlias /* AS is ok for column aliases ... */
FROM TableALong A /* ... but not for table aliases */
LEFT OUTER JOIN TableBLong B /* JOIN syntax */
ON (A.NAME = B.NAME and A.STORE = B.STORE)
WHERE ...
Run Code Online (Sandbox Code Playgroud)
而不是LEFT OUTER你可以有INNER, FULL OUTER, ...; 请参阅此处了解更多信息。