Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>probable cause: it is selecting data from 2 tables (tbl_teams and tbl_games) <br> The condition is that tbl_teams.team_ID equals team2_ID <em>and</em> team1_ID. Unless there are games where the same team was on both sides, that's never going to work. </p> <p>You didn't specify what you want the query to return, so I'll assume you just want the results for both teams.</p> <p>What you probably want is a join that involves 3 sets of data: game, the first team, the second team. in SQL this can be done using an alias.</p> <p>try this:</p> <pre><code>SELECT tbl_games.game_ID, tbl_games.game_date, team1.team_name as "team1_name", team2.team_name as "team2_name" FROM tbl_teams as team1, tbl_teams as team2, tbl_games WHERE tbl_games.team1_ID = team1.team_ID AND tbl_games.team2_ID = team2.team_ID AND tbl_games.team1_score IS NULL AND tbl_games.team2_score IS NULL; </code></pre> <p>Adding the "is null" will reduce the results. If all games have a score, you won't get any results.</p> <p>Another potential issue with your query is that the field names are between single quotes. I'm not sure those are removed by php before actually executing the query. If they're not, that's bad; anything between single quotes is treated as a string. That would mean the condition <code>'tbl_games.team1_score' IS NULL</code> is actually comparing string 'tbl_games.team1_score' with null and not the content of the field named team1_score.</p> <p>Edit: added the is NULL to the where clause as in the example data you do have nulls.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload