Wednesday, 22 June 2016

Java Interview SQL Directive : Order of operation (SQL Questions)

Q: Define the order in operation in which SQL directive gets executed.

A:
  1. FROM clause
  2. WHERE clause
  3. GROUP BY clause
  4. HAVING clause
  5. SELECT clause
  6. ORDER BY clause
First it is going to run the From clause to get the tables.
Then the WHERE clause to filter it. That is why FROM AS names are available in WHERE. EX: (select st.name  as newName from student st where st.age > 30 order by newName)
Then the GROUP BY AND HAVING to sum the groups and filter groups.
Then comes the SELECT clause.
In the last the ORDER BY , and the AS names from Select are available in ORDER BY clause.
More interview questions to follow.

No comments:

Post a Comment