[ Prev ]
2019-11-13

-- Nov 13 In-Class Exercise Thread
1) SELECT * FROM EMPLOYEES WHERE employee.name AND year.started
2) SELECT * FROM EMPLOYEES JOIN employee.name ON year.started
2nd method is better because this table joins employee name with year started directly without creating tuples started in 1st method.
1) SELECT * FROM EMPLOYEES WHERE employee.name AND year.started 2) SELECT * FROM EMPLOYEES JOIN employee.name ON year.started 2nd method is better because this table joins employee name with year started directly without creating tuples started in 1st method.

-- Nov 13 In-Class Exercise Thread
1. SELECT * FROM Student, Professor WHERE Student.class = Professor.class 2. SELECT * FROM Student JOIN Professor ON Student.class = Professor.class JOIN ON syntax would be better because it is more readable and obvious that it is a join and under what condition things are being joined.
1. SELECT * FROM Student, Professor WHERE Student.class = Professor.class 2. SELECT * FROM Student JOIN Professor ON Student.class = Professor.class JOIN ON syntax would be better because it is more readable and obvious that it is a join and under what condition things are being joined.

-- Nov 13 In-Class Exercise Thread
SELECT Airplane, Airline FROM Airports, City WHERE Airline.name = Southwest;
SELECT Airplane, Airline FROM(Airports JOINS City ON Airline.name = Southwest);
The second query is better because both the queries perform the same result but the second query would not create unnecessary data.
SELECT Airplane, Airline FROM Airports, City WHERE Airline.name = Southwest; SELECT Airplane, Airline FROM(Airports JOINS City ON Airline.name = Southwest); The second query is better because both the queries perform the same result but the second query would not create unnecessary data.

-- Nov 13 In-Class Exercise Thread
- Table 1: Students(id, name, courseId), table 2: Courses(id, courseName, instructorId), table 3: Instructors(id, name)
 SELECT Instructors.name from Students, Courses, Instructors WHERE Students.courseId = Courses.id AND Courses.instructorId = Instructors.id
 SELECT name from (Instructors JOIN Courses, Students ON id = Courses.courseId AND Courses.courseId = Students.courseId)
JOIN ON syntax is better because it's clearer that we want "name" from Instructors instead of Students
- Table 1: Students(id, name, courseId), table 2: Courses(id, courseName, instructorId), table 3: Instructors(id, name) SELECT Instructors.name from Students, Courses, Instructors WHERE Students.courseId = Courses.id AND Courses.instructorId = Instructors.id SELECT name from (Instructors JOIN Courses, Students ON id = Courses.courseId AND Courses.courseId = Students.courseId) JOIN ON syntax is better because it's clearer that we want "name" from Instructors instead of Students

-- Nov 13 In-Class Exercise Thread
SELECT * FROM (MovieStar, StarIn) WHERE title = movieTitle)
SELECT *FROM MovieStart JOIN StarIn on title = movieTitle
the JOIN ON query is more readable and simper
SELECT * FROM (MovieStar, StarIn) WHERE title = movieTitle) SELECT *FROM MovieStart JOIN StarIn on title = movieTitle the JOIN ON query is more readable and simper

-- Nov 13 In-Class Exercise Thread
 Employees(name,salary)
 Students(name,tuition)
 1. 
 select *
 from Employees, Students
 where Employees.name = Students.name
 2. 
 select * 
 from (Employees Join Students on Employees.name = Students.name)
 reasons:
 1.they have the same result but Cartesian product need to do n*M rows first (2X2 ) rows here, then filter the rows, whereas join only filter out the result.
 
Employees(name,salary) Students(name,tuition) 1. select * from Employees, Students where Employees.name = Students.name 2. select * from (Employees Join Students on Employees.name = Students.name) reasons: 1.they have the same result but Cartesian product need to do n*M rows first (2X2 ) rows here, then filter the rows, whereas join only filter out the result.

-- Nov 13 In-Class Exercise Thread
Singer(name, address, DOB, genre) Band(name, SingerName, address, studio) 1. SELECT name, address FROM Singer, Band WHERE name = SingerName AND address = address; 2. SELECT name, address FROM Singer NATURAL JOIN Band ON name.Singer = SingerName.band AND address.Singer = address.Band; The two Sql query will yield the same result, however, number one is better because the query command is simpler.
Singer(name, address, DOB, genre) Band(name, SingerName, address, studio) 1. SELECT name, address FROM Singer, Band WHERE name = SingerName AND address = address; 2. SELECT name, address FROM Singer NATURAL JOIN Band ON name.Singer = SingerName.band AND address.Singer = address.Band; The two Sql query will yield the same result, however, number one is better because the query command is simpler.

-- Nov 13 In-Class Exercise Thread
1. SELECT name, address FROM Singer, Band WHERE name = SingerName AND address = address; 2.SELECT name, address FROM Singer NATURAL JOIN Band ON name.Singer = SingerName.band AND address.Singer = address.Band; The two Sql query will give the same result.
1. SELECT name, address FROM Singer, Band WHERE name = SingerName AND address = address; 2.SELECT name, address FROM Singer NATURAL JOIN Band ON name.Singer = SingerName.band AND address.Singer = address.Band; The two Sql query will give the same result.

-- Nov 13 In-Class Exercise Thread
 1. SELECT datacenter FROM region, availZone WHERE id=rid AND id=1;
 2. SELECT datacenter FROM (region JOIN availZone ON id=rid AND id=1); 
 The 2nd query would be better because it is more explicit to the reader on exactly what is being joined.
1. SELECT datacenter FROM region, availZone WHERE id=rid AND id=1; 2. SELECT datacenter FROM (region JOIN availZone ON id=rid AND id=1); The 2nd query would be better because it is more explicit to the reader on exactly what is being joined.

-- Nov 13 In-Class Exercise Thread
SELECT Airplane, Airline FROM Airports, City WHERE Airline.name = Southwest; SELECT Airplane, Airline FROM(Airports JOINS City ON Airline.name = Southwest); The second query is better because both the queries perform the same result but the second query would not create unnecessary data.
SELECT Airplane, Airline FROM Airports, City WHERE Airline.name = Southwest; SELECT Airplane, Airline FROM(Airports JOINS City ON Airline.name = Southwest); The second query is better because both the queries perform the same result but the second query would not create unnecessary data.
[ Next ]
X