title: Column does not exist in PostgreSQL DB
body: <blockquote>
    <p>Returns:
          A list of tuples, each of which contains (id, name, wins, matches):
            id: the player's unique id (assigned by the database)
            name: the player's full name (as registered)
            wins: the number of matches the player has won
            matches: the number of matches the player has played</p>
  </blockquote>
  
  <p>my sql script is the following:</p>
  
  <pre><code>--if the DB already exists drop it so i can create it again
  DROP DATABASE IF EXISTS tournament; 
  --create DB and connect to it
  CREATE DATABASE tournament;
  \c tournament;
  --create table for players
  CREATE TABLE players (
      id SERIAL, 
      name TEXT, 
      PRIMARY KEY (id)
  ); 
  --create table for matches
  CREATE TABLE matches (
      id_match SERIAL, 
      id_winner INTEGER NULL REFERENCES players(id),
      id_looser INTEGER NULL REFERENCES players(id),
      PRIMARY KEY (id_match)
  );
  --create the view to count all the wins of a player
  CREATE VIEW countWins AS
      SELECT players.id AS ID,players.name AS Name,coalesce(count(matches.id_winner),0) as Record
      FROM players, matches WHERE players.id = matches.id_winner
      GROUP BY players.id;
  --create the view for all the matches a players has played
  CREATE VIEW countMatches AS
      SELECT players.id AS ID,players.name AS Name,count(*) AS Played
      FROM players, matches WHERE players.id = matches.id_winner OR players.id = matches.id_looser
      GROUP BY players.id;
  --
  CREATE VIEW standings AS
      SELECT countMatches.ID,countMatches.Name,coalesce(countWins.Record,0) AS wins,countMatches.Played
      FROM countMatches LEFT JOIN countWins
      ON countWins.ID = countMatches.ID or wins = 0
      ORDER BY wins DESC;
  </code></pre>
  
  <p>when I run the </p>
  
  <blockquote>
    <p>\i tournament.sql</p>
  </blockquote>
  
  <p>in the command line I get this error:</p>
  
  <pre><code>DROP DATABASE
  CREATE DATABASE
  You are now connected to database "tournament" as user "vagrant".
  CREATE TABLE
  CREATE TABLE
  CREATE VIEW
  CREATE VIEW
  psql:tournament.sql:42: ERROR:  column "wins" does not exist
  LINE 4:  ON countWins.ID = countMatches.ID or wins = 0
  </code></pre>
  
  <p>I don't understand why is saying column wins does not exist if I'm creating it on "standings" view...</p>