SQL Exercise 1 - Interview
SQL Exercise 1 - Interview
Write an SQL statement that lists school names, student names, and their cities only if the
school and the student are in the same city and the student is not from New York.
Table: school
school_id school_name city
----------- ------------------ ----------
1 Stanford Stanford
2 University of Cali San Francisco
3 Harvard University New York
4 MIT Boston
5 Yale New Haven
Table: student
student_id student_name city school_id
----------- ------------ ---------- -----------
1001 Peter Brebec New York 1
1002 John Goorgy San Francisco 2
2003 Brad Smith New York 3
1004 Fabian Johns Boston 5
1005 Brad Cameron Stanford 1
1006 Geoff Firby Boston 5
1007 Johnny Blue New Haven 2
1008 Johse Brook Miami 2
Table: subject
subject_id subject_name max_score lecturer
---------- ---------- ---------- -----------
11 Math 130 Christena Solem
12 Computer Science 150 Jaime Pille
13 Biology 300 Carrol Denmark
14 Geography 220 Yuette Galang
15 Physics 110 Colton Rather
16 Chemistry 400 Nan Mongeau
Table: student
student_id student_name city subject_id
----------- ------------ ---------- -----------
2001 Thurman Thorn New York 11
2002 Sharda Clemens San Francisco 12
2003 Buck Elkins New York 13
2004 Fabian Johns Boston 15
2005 Brad Cameron Stanford 11
2006 Sofia Roles Boston 16
2007 Rory Pietila New Haven 12
Table: worker
id name
--- -----------
1 Guillermo Sparks
2 Gene Roberts
3 Ally Jones
4 Bryant Summers
5 Candice Green
Table: departments
id name manager_id
--- ------------- ---------
1 Financial 3
2 Strategy 5
3 IT 1
4 Marketing NULL
Table: student
student_id student_name city subject_id
----------- ------------ ---------- -----------
2001 Thurman Thorn New York 11
2002 Sharda Clemens San Francisco 12
2003 Buck Elkins New York 13
2004 Fabian Johns Boston 15
2005 Brad Cameron Stanford 11
2006 Sofia Roles Boston 16
2007 Rory Pietila New Haven 12
2008 Cicely Weish Tulsa 14
2011 Richard Curtin Boston 11
2012 Kassy Ledger Stanford 11
2013 Henry Ledger Miami 13
2014 Darius Fidzberg San Francisco 12
2015 Darcey Fiorillo Chicago 14
Table: subject
subject_id subject_name max_score lecturer
---------- ---------- ---------- -----------
11 Math 130 Christena Solem
12 Computer Science 150 Jaime Pille
13 Biology 300 Carrol Denmark
14 Geography 220 Yuette Galang
15 Physics 110 Colton Rather
16 Chemistry 400 Nan Mongeau
Table: student
student_id student_name city subject_id
----------- ------------ ---------- -----------
2001 Thurman Thorn New York 11
2002 Sharda Clemens San Francisco 12
2003 Buck Elkins New York 13
2004 Fabian Johns Boston 15
2005 Brad Cameron Stanford 11
2006 Sofia Roles Boston 16
2007 Rory Pietila New Haven 12