2016-10-22 35 views
2

我想從Oracle中的查詢基本上看起來像這樣得到的唯一一對值:獲取從一個表列不同對

select a.name, b.name 
from table1 a 
join table1 b on a.attribute = b.attribute 

現在,這應該給我一串類似的重複值

  • 蘋果,香蕉
  • 橙,獼猴桃
  • 香蕉,蘋果
  • 獼猴桃,橘子

而是我只是得到

  • 蘋果,蘋果
  • 香蕉,香蕉
  • 獼猴桃,獼猴桃
  • 橘,橙

當我添加

select a.name, b.name 
from table1 a 
join table1 b on a.attribute = b.attribute 
where a.attribute < b.attribute 

我得到「未選擇行」

,我不知道我做錯了,請請幫助

+0

你可能需要'where a.name mathguy

回答

1

可以省略使用a.name <> b加入相同的名稱。名稱

select a.name, b.name from table1 a 
join table1 b 
on a.name <> b.name  
+0

謝謝我在任何地方都找不到 –

1

看來,兩個表中的相同屬性對應於相同的名稱。 如果您使用

on a.attribute != b.attribute 

您將得到每一對可能的不同名稱。 如果仍然對相同的名稱,你可以添加

where a.name != b.name 

是你需要什麼?