我有以下问题。我有 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
我想在加入之前做一些类似 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
这在oracle中是无效的。让它在 oracle 中工作的正确查询是什么?我假设这是我想要的左连接? (join后,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 ...
您可以使用 INNER
、FULL OUTER
,而不是 LEFT OUTER
,...;见here了解更多。
关于sql - 如何在oracle中为两个表执行别名连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36364200/