C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
SQL ClausesThe following are the various SQL clauses: 1. GROUP BY
Syntax SELECT column FROM table_name WHERE conditions GROUP BY column ORDER BY column Sample table: PRODUCT_MAST
Example: SELECT COMPANY, COUNT(*) FROM PRODUCT_MAST GROUP BY COMPANY; Output: Com1 5 Com2 3 Com3 2 2. HAVING
Syntax: SELECT column1, column2 FROM table_name WHERE conditions GROUP BY column1, column2 HAVING conditions ORDER BY column1, column2; Example: SELECT COMPANY, COUNT(*) FROM PRODUCT_MAST GROUP BY COMPANY HAVING COUNT(*)>2; Output: Com1 5 Com2 3 3. ORDER BY
Syntax: SELECT column1, column2 FROM table_name WHERE condition ORDER BY column1, column2... ASC|DESC; Where ASC: It is used to sort the result set in ascending order by expression. DESC: It sorts the result set in descending order by expression. Example: Sorting Results in Ascending OrderTable: CUSTOMER
Enter the following SQL statement: SELECT * FROM CUSTOMER ORDER BY NAME; Output:
Example: Sorting Results in Descending OrderUsing the above CUSTOMER table SELECT * FROM CUSTOMER ORDER BY NAME DESC; Output:
Next TopicDBMS SQL Aggregate function
|