Home » SQL & PL/SQL » SQL & PL/SQL » Problems with Self_join
Problems with Self_join [message #264557] Mon, 03 September 2007 14:01 Go to next message
binho_sjc
Messages: 8
Registered: April 2007
Junior Member
Please I need some help with self join.

How could I eliminate duplicated results from a self join?
I have this sql:

select a.name,b.name,a.country
from emp a,emp b
where a.name <> b.name
and a.country = b.country

The result is something like

John Peter USA
Peter John USA
John James USA
James John USA
James Peter USA
Peter James USA

How could I get just 3 rows instead 6 ?

Sorry by english . I am brazilian.

Thanks and hugs to everybody !!!! Enjoy the life !!!


Robson Ivo



Re: Problems with Self_join [message #264558 is a reply to message #264557] Mon, 03 September 2007 14:05 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Use something like
where a.name > b.name
Re: Problems with Self_join [message #264570 is a reply to message #264558] Mon, 03 September 2007 14:40 Go to previous message
binho_sjc
Messages: 8
Registered: April 2007
Junior Member
Thank you very much.

It works perfectly.

Previous Topic: wanted SELECT Quesry to restrict count of the user selecting the record
Next Topic: How can i drop all tables in a database schema with delete message prompt ??
Goto Forum:
  


Current Time: Thu Dec 08 10:42:22 CST 2016

Total time taken to generate the page: 0.08814 seconds