Hi! I\'m studying for my final and can\'t figure out how sql is processing this
ID: 3643176 • Letter: H
Question
Hi! I'm studying for my final and can't figure out how sql is processing this query to get the response. I was hoping someone could break it down line by line how it's comparing each field and explain to me how it get's the result it get's. In addition - is there anyway to place a "tracer" in access sql? For example in Java I would put printlines everywhere to tell me what step the program was on when doing it's analysis. How could I go about doin that with these? Thanks!
Query: SELECT a.deptname FROM emp as A, emp AS b
WHERE a.bossno = b.empno AND a.empsalary > b.empsalary OR a.deptname = 'Management'
Result:
Management
Management
Management
Management
Management
Management
Management
Purchasing
Management
Management
Explanation / Answer
Consider this as comparision of two different tables a and b, though they happen to be the same table. Now, take each row of 'a' and compare with each row of table 'b'. If the conditions are satisfied, then output the result. Lets go through this example step by step. Take the first row of 'a' and compare with every row of 'b', starting from the first row. Here, first row (alice) is compared with first row of b (alice), condition satisfied, output "Management" first row (alice) is compared with second row of b (ned), condition satisfied, output "management" Goes on for all rows --> total of 9 "management" outputs, one for each comparision of alice with each row of b Now, second row of a (ned) compared with first row of b (alice), condition failed, no output ... This goes on for all rows The "purchasing" output is when sarah (from table a) and brier (from table b) are compared. For your query about a "tracer", it is not possible in sql, as the databases are very big and each query takes a lot of time to process. No such tracer is available.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.