我有以下问题。我有两张桌子要加入" 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中使用它的正确查询是什么?我认为这是我想要的左连接? (在连接之后,TableALong中的每个项目都会有多行。)
答案 0 :(得分:2)
固定查询:
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 ...
而不是LEFT OUTER
您可以拥有INNER
,FULL OUTER
,...;有关详情,请参阅here。