Skip to content

Instantly share code, notes, and snippets.

@bobbravo2
Last active June 23, 2017 17:10
Show Gist options
  • Save bobbravo2/ea0992d7f9d5d348cde41a2322fd73a9 to your computer and use it in GitHub Desktop.
Save bobbravo2/ea0992d7f9d5d348cde41a2322fd73a9 to your computer and use it in GitHub Desktop.

Look at script_lines.character_id == characters.id AND script_lines.episode_id == episodes.id which gives us the title and original_air_date

Query multiple tables (episodes, characters) - Find when the character moe szyslak first appears.

Part 2

Refactor our SQL to use JOINS

 SELECT * FROM `script_lines`, `characters`, `episodes`
	WHERE `characters`.`name` = 'moe szyslak'
	AND `characters`.`id` = `script_lines`.`character_id`
	AND `script_lines`.`episode_id` = `episodes`.`id`
	ORDER BY `episodes`.`original_air_date`
	LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment