Home » SQL & PL/SQL » SQL & PL/SQL » Query to find different league matches between team, no repeatitive league matches (only once) (Oracle 11g R1 Linux)
Query to find different league matches between team, no repeatitive league matches (only once) [message #608615] Fri, 21 February 2014 06:58 Go to next message
anil_mk
Messages: 146
Registered: August 2006
Location: Bangalore, India
Senior Member

CREATE TABLE TEAM(team_id NUMBER, team_name VARCHAR2(20))
/
INSERT INTO TEAM (SELECT 1,'TeamA' FROM DUAL UNION SELECT 2,'TeamB' FROM DUAL UNION SELECT 1,'TeamC' FROM DUAL)
/
COMMIT
/
SELECT * FROM TEAM
/
/*Team_id		Team_Name
------------------------
1		TeamA
2		TeamB
3		TeamC

*/


Please let me know query to display below output

Team_Name Opponent_Team
-------------------------------
TeamA TeamB
TeamA TeamC
TeamB TeamC

Thanks,
Anil MK
Re: Query to find different league matches between team, no repeatitive league matches (only once) [message #608617 is a reply to message #608615] Fri, 21 February 2014 07:11 Go to previous messageGo to next message
John Watson
Messages: 8931
Registered: January 2010
Location: Global Village
Senior Member
Would I be right to think that this is a college homework question? If so, post the SQL you have tried so far. And, by the way, your INSERT statements do not not match the result of the SELECT.
Re: Query to find different league matches between team, no repeatitive league matches (only once) [message #608618 is a reply to message #608615] Fri, 21 February 2014 07:11 Go to previous messageGo to next message
Littlefoot
Messages: 21808
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
I guess you've made a typo - TeamC's ID should have been "3"; right?

If that's so, here's one option:
SQL> select t1.team_name, t2.team_name
  2  from team t1, team t2
  3  where t1.team_id < t2.team_id
  4  order by t1.team_name;

TEAM_NAME            TEAM_NAME
-------------------- --------------------
TeamA                TeamB
TeamA                TeamC
TeamB                TeamC

SQL>
icon7.gif  Re: Query to find different league matches between team, no repeatitive league matches (only once) [message #608620 is a reply to message #608618] Fri, 21 February 2014 07:25 Go to previous messageGo to next message
anil_mk
Messages: 146
Registered: August 2006
Location: Bangalore, India
Senior Member


Yes there was a typo. Thank you Littlefoot for the query.

Regards,
Anil MK
Re: Query to find different league matches between team, no repeatitive league matches (only once) [message #608632 is a reply to message #608620] Fri, 21 February 2014 08:12 Go to previous message
msol25
Messages: 396
Registered: June 2011
Senior Member
hi,

Please read basic sql queries.Please find url:

http://www.th-nuernberg.de/fileadmin/Rechenzentrum/Virtuohm/Vorlesungen/Hopf/SQL1.pdf
Previous Topic: Need to put results of SQL into a table
Next Topic: Perform minus operation between two Pl/SQL Record Type Tables
Goto Forum:
  


Current Time: Fri Apr 26 05:39:10 CDT 2024