Skip to content

Instantly share code, notes, and snippets.

@toreriklinnerud
Created August 17, 2011 17:15
Show Gist options
  • Save toreriklinnerud/1152050 to your computer and use it in GitHub Desktop.
Save toreriklinnerud/1152050 to your computer and use it in GitHub Desktop.
Example database view
DROP VIEW IF EXIXTS student_views;
CREATE VIEW student_views AS
SELECT
students.id AS id,
students.name AS name,
teachers.name AS teacher_name,
schools.name AS school_name,
countries.name AS country_name
FROM students
LEFT JOIN teachers ON teachers.id = students.teacher_id
LEFT JOIN schools ON schools.id = students.school_id
LEFT JOIN countries ON countries.id = students.country_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment