Saturday, January 10, 2015

Understanding Oracle SELECT SQL Query Syntax

One SELECT SQL query consists of below keyword.
  • SELECT : it list all column to be shown in resultant set
    SELECT empName, empId FROM employee;
  •  FROM : consist of one or more table name from which you want to get the result
    SELECT e.empName, e.empId, e.departmentId,  d.departmentName FROM employee e, department d;
  •   WHERE : it is used to filter the result set
    SELECT Lname, Fname FROM employee WHERE Lname = ‘Yadav’;
  •  GROUP BY : it is used in combination with Aggregate functions such as COUNT, SUM, AVG
    SELECT * FROM employee GROUP BY departmentId;
  •  HAVING: this is again use to filter the result set and similar to Where clause. In WHERE clause the search condition on the row is performed before rows are grouped whereas in cas of HAVING, groups are formed first and then search condition is applied to the group. You can use WHERE & HAVING clause together. Only columns in GROUPBY statement is used for the HAVING clause.
    SELECT * FROM employee GROUP BY departmentId HAVING departmentId = 10;
  •  ORDER BY: it is used to arrange the result set in ascending order or descending order
    SELECT Lname, Fname FROM employee ORDER BY Lname DESC;
  •  STARTING WITH: It works with the conjunction with the WHERE clause. It is similar to like clause
    SELECT Lname, Fname FROM employee WHERE Lname STARTING WITH (‘Y%’);


Similarly we have more keywords like BETWEEN, IN, LIKE and many more. But above one are mainly used keywords in SELECT sql

No comments:

Post a Comment