Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I was asked what "=" and "IN" really do. Let us say we have two tables,
- Positions(EmployeeID, JobID, Season, Year). Those who got a job.
- Applications(EmployeeID, Year, Season, JobID) The applications for jobs.
- If I say SELECT Positions.EmployeeID FROM Positions, Applications WHERE Positions.JobID = Applications.JobID; what does it do?
- Does it select only the ones where there is, for every JobID in the Positions table, an entry with the same JobID in Applications?
- If Applications had only one entry and that entry had an JobID = 6, then every entry with the same ID in Positions show.
- How is IN any different?
- What if we nest them?
- SELECT Positions.EID
- FROM Positions, Applications
- WHERE Positions.JobID NOT IN --Filter out those who have the same JobID as in the temporary table created below
- (SELECT Applications.JobID FROM Applications WHERE Applications.EID=Positions.EID) --the IDs where we have a match
- AND Positions.EID=Applications.EID --Remove all entries that also do not have the same EID
- GROUP BY Applications.EID
- HAVING 3<count(Applications.EID);
- Will it change if I change IN into =?
- SELECT Positions.EID
- FROM Positions, Applications
- WHERE Positions.JobID != --Filter out those who have the same JobID as in the temporary table created below
- (SELECT Applications.JobID FROM Applications WHERE Applications.EID=Positions.EID) --the IDs where we have a match
- AND Positions.EID=Applications.EID --Remove all entries that also do not have the same EID
- GROUP BY Applications.EID
- HAVING 3<count(Applications.EID);
Advertisement
Add Comment
Please, Sign In to add comment