If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > avoiding duplicate lines

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-04, 18:16
sps sps is offline
Registered User
 
Join Date: Aug 2004
Location: Cary, NC
Posts: 110
avoiding duplicate lines

I have a oracle database that includes the following tables:

game(gameID, season, week, stadium) -- gameID is PK

competesIn(gameID, team, score) -- gameID, teamName is PK

As you can probably infer, it is a database to track the results of football games.

competesIn has two records for every game, one for each team.

I would like to create a view that combines these tables into the following structure

gameView(season, week, location, team1, score1, team2, score2)

I have tried using the following SQL inside the view:

Code:
select g.season, g.week, g.stadium, 
  c1.team as team1, c1.score as Score1, 
  c2.team as team2, c2.score as Score2 
  from game g, competesIn c1, competesIn c2 
  where c1.gameID = g.gameID 
  and c2.gameID = g.gameID 
  and c1.team != c2.team
This does create the view I was looking for but it creates two rows for each game and I need it to return only one row per game.

Any thoughts?
__________________

Steve
Reply With Quote
  #2 (permalink)  
Old 11-06-04, 18:25
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
change != in last line to <
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On