CREATE VIEW current_planet_stats AS
SELECT p.pid, p.nick, p.planet_status, p.hit_us, ps.x, ps.y, ps.z, p.ruler, p.planet, p.race
	,alliance, a.relationship, a.aid, p.channel, p.ftid, p.gov
	,ps.size, ps.score, ps.value, ps.xp, ps.sizerank, ps.scorerank, ps.valuerank, ps.xprank
FROM ( SELECT pid, tick, x, y, z, size, score, value, xp, sizerank, scorerank, valuerank, xprank
		FROM planet_stats
		WHERE tick = ( SELECT max(tick) AS max FROM planet_stats)
	) ps
	NATURAL JOIN planets p
	LEFT JOIN alliances a USING (alliance);

CREATE OR REPLACE VIEW current_planet_stats_full AS
SELECT *
FROM planets p
	NATURAL JOIN (
		SELECT *
		FROM planet_stats
		WHERE tick = ( SELECT max(tick) AS max FROM planet_stats)
	) ps
	LEFT JOIN alliances USING (alliance);
