Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to restrict FROM in SQL
    primarykey
    data
    text
    <p>Sorry if the question's title doesn't mean anything, I'm still a beginner and I just don't know how to explain it.</p> <p>Here's my current SQL query that works fine</p> <pre><code>select teams.id as team_id, teams.team_name, players.type_name, sum(points) as points from teams inner join gameweeks on teams.id = gameweeks.team_id inner join gameweeks_players on gameweeks.id = gameweeks_players.gameweek_id inner join players on gameweeks_players.player_id = players.id inner join player_fixtures on players.id = player_fixtures.player_id AND player_fixtures.gw_number = gameweeks.number group by teams.id, players.type_name </code></pre> <p>In rails, I translated this query into </p> <pre><code>Team.joins(gameweeks: :players). joins("inner join player_fixtures on players.id = player_fixtures.player_id AND player_fixtures.gw_number = gameweeks.number"). group("teams.id, players.type_name"). select("teams.id, teams.team_name, players.type_name as type, sum(points) as points") </code></pre> <p>In rails, I have these 2 models.</p> <pre><code>class League &lt; ActiveRecord::Base belongs_to :user has_many :league_teams has_many :teams, :through =&gt; :league_teams end class Team &lt; ActiveRecord::Base has_many :gameweeks has_many :league_teams has_many :leagues, :through =&gt; :league_teams end </code></pre> <p>I would like to modify my query to only the teams that are associated with a league (I'd like to pass the ID of that league somehow)</p> <p>I just don't know how to do that and I'm missing the knowledge to google it with the right keywords...</p> <p>Could you point me in the right direction please?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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