faction_id marker_id cycle_id
14 1 1
14 2 1
12 2 2
12 3 2
I am trying to grab both entries with cycle_id 2, ignoring marker 2 in cycle 1, but still returning marker 1 in cycle 1. This is so I can display all the current data (most recent cycle) and only display markers that have not changed faction_id in previous cycles.
Right now, I am simply returning the whole table ordering it based on cycle_id and overwriting old cycle data in a PHP array when the data is returned, but this won't be an efficient way of handling it when the database get's larger.
My current select statement: (all of these columns are within tok_ownership)
SELECT tok_marker.id as id,
tok_marker.name as name,
tok_marker.lat as lat,
tok_marker.lng as lng,
tok_faction.colour as colour,
tok_ownership.war_conditions as war_conditions,
tok_ownership.improvements as improvements,
tok_ownership.poa as poa
FROM tok_ownership
JOIN tok_marker ON tok_marker.id=tok_ownership.marker_id
JOIN tok_faction ON tok_faction.term_id=tok_ownership.faction_id
ORDER BY tok_ownership.cycle_id ASC;
tok_ownership
1 marker_id mediumint(8)
2 faction_id mediumint(8)
3 cycle_id mediumint(8)
4 victory_id smallint(6)
5 war_conditions varchar(64)
6 improvements varchar(64)
7 active_effects text
8 poa tinyint(3)
tok_marker
1 id mediumint(8)
2 name varchar(64)
3 lat decimal(10,7)
4 lng decimal(10,7)
tok_faction
1 term_id smallint(6)
2 colour char(6)
tok_cycle
1 id int(10)
2 week date