Sql does not return column name

Asked

Viewed 123 times

0

I have two tables a TEAM another MATCH_DETAILS. The table TEAM has the spine id and is a primary key. I made two table reports TEAM for MATCH_DETAILS. In the MATCH_DETAILS assumed as foreign key team_id and team_id1.

With the following query:

SELECT  
  team_name, team_id1, Umpire_name, 
  playermatch_name, score_id
FROM 
  Match_details m, Team t, 
  Umpire u, player_match p, Score s
WHERE m.TEAM_TEAM_ID = t.TEAM_ID 
  and m.TEAM_TEAM_ID1 =  m.TEAM_TEAM_ID1 
  and m.UMPIRE_UMPIRE_ID = u.UMPIRE_ID 
  and p.Match_details_MATCH_ID = m.match_id 
  and s.Match_details_MATCH_ID = m.match_id;

Returns the following:

printscreen do header da tabela tag

I think Chelsea has a way id number 1 the id number 2 in column team_id1 corresponds to me liverpool. What I intend to do is show up Liverpool and not the id which corresponds.

1 answer

0

First, I suggested using explicit junctions rather than implicit junctions (ANSI-92). Although there are no performance differences, the "new" syntax is much more readable when there are many tables involved (as is your case).

That being said, your query can be rewritten as follows.

SELECT  T1.TEAM_NAME,
        T2.TEAM_NAME, 
        U.Umpire_name, 
        playermatch_name,
        score_id
  FROM Match_details m_d, 
 INNER JOIN Team T1  -- Detalhes da primeira equipa
    ON T1.TEAM_ID = m_d.TEAM_ID
 INNER JOIN Team T2  -- Detalhes da segunda equipa
    ON T2.TEAM_ID = m_d.TEAM_ID1
 INNER JOIN Umpire U
    ON U.UMPIRE_ID = m_d.UMPIRE_UMPIRE_ID
 INNER JOIN player_match P
    ON P.Match_details_MATCH_ID = m_d.match_id 
 INNER JOIN Score S
    ON S.Match_details_MATCH_ID = m_d.match_id

Note the double junction in the TEAM table: One for the first team (in his example Chelsea) and another for the second team (Liverpool). To show the name of the second team in the result, simply select the name of the respective table (T2) instead of the ID.

  • I tried your suggestion and it didn’t work presents the following error:ORA-00933: SQL command was not finished correctly 00933. 00000 - "SQL command not properly ended"

  • @Dianamadeira, I edited the answer. Missing include "JOIN" in two of the junctions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.