SQL JOIN clause

The JOIN are used to combine the records from two or more tables. Types of SQL JOIN: SQL INNER JOIN. SQL LEFT OUTER JOIN. SQL RIGHT OUTER JOIN. SQL FULL OUTER JOIN. SQL SELF JOIN. SQL CARTESIAN JOIN or CROSS JOIN.   Next Topic: SQL INNER JOIN with example. Previous Topic: SQL HAVING clause with … Read more

Categories SQL

SQL HAVING clause

The HAVING clause is used with the GROUP BY clause and filter the groups created by the GROUP BY clause. Syntax: SELECT column1, column2,…, columnN FROM tableName WHERE[conditions] GROUP BY column1, column2 …HAVING[conditions]; Example: SELECT EMP_NAME, SUM(SALARY) FROM EMPLOYEE GROUP BY EMP_NAME HAVING Count(EMP_NAME) >= 2;SELECT EMP_NAME, SUM(SALARY) FROM EMPLOYEE GROUP BY EMP_NAME HAVING Count(EMP_NAME) … Read more

Categories SQL

SQL GROUP BY clause

The GROUP BY clause is used to group the identical data by one or more columns. It is used with the aggregate functions in the select statement. Syntax: SELECT column1, column2,…, columnN FROM tableName WHERE[conditions] GROUP BY column1, column2 …;  Example: SELECT EMP_NAME, SUM(SALARY) FROM EMPLOYEE GROUP BY EMP_NAME;SELECT EMP_NAME, SUM(SALARY) FROM EMPLOYEE GROUP BY … Read more

Categories SQL

SQL ORDER BY Clause

The ORDER BY Clause is used to sort the results either in ascending or descending order based on one or more columns. Oracle and some other database sorts query results in ascending order by default. Syntax: SELECT * FROM tableName [WHERE condition] [ORDER BY column1, column2,…,columnN] [ASC | DESC]; Where ASC keyword is used for … Read more

Categories SQL

SQL LIKE operator

The LIKE operator is used in a WHERE clause to retrieve all records of a table whose specified column values match a specified pattern. The percent sign Syntax: SELECT * FROM tableName WHERE columnName LIKE pattern; Example: SELECT * FROM EMPLOYEE WHERE EMP_NAME LIKE ‘P%’;SELECT * FROM EMPLOYEE WHERE EMP_NAME LIKE ‘P%’; Output: EMP_ID EMP_NAME … Read more

Categories SQL

SQL UNION Operator

SQL UNION Operator. The UNION operator is used to combine the result sets of two or more SELECT statements. For UNION, every SELECT statement must have same number of columns with same data type and must be in same order. It will return the distinct values by removing the duplicate rows. Syntax: SELECT columnList FROM … Read more

Categories SQL

SQL OR Clause

The OR clause is also known as conjunctive operator and used to combine multiple conditions in SQL statement. Syntax: SELECT * FROM tableName WHERE [condition1] OR [condition2]…OR [conditionN]; In case of OR clause any one of the conditions separated by OR should be true. Example: SELECT * FROM EMPLOYEE WHERE SALARY > 40000 OR AGE … Read more

Categories SQL

SQL AND Clause

The AND clause is also known as conjunctive operator and used to combine multiple conditions in SQL statement. Syntax: SELECT * FROM tableName WHERE [condition1] AND [condition2]…AND [conditionN]; In case of AND clause all conditions should be true. Example: SELECT * FROM EMPLOYEE WHERE SALARY > 40000 AND AGE < 29;SELECT * FROM EMPLOYEE WHERE … Read more

Categories SQL

SQL WHERE Clause

The WHERE clause is used to add a condition to filter the records when we want to fetch the specific records instead of all records. Syntax: SELECT * FROM tableName WHERE [condition];  To specify a condition we can use any logical operator like >, <, =, LIKE, NOT etc. Example: SELECT * FROM EMPLOYEE WHERE … Read more

Categories SQL

SQL ALIAS Statement

The ALIAS statement is used to temporarily rename a table or column in a SQL statement. Syntax: SELECT columnName AS columnAliasName FROM tableName As tableAliasName; Example: SELECT EMP_NAME AS NAME FROM EMPLOYEE WHERE EMP_ID = 1;SELECT EMP_NAME AS NAME FROM EMPLOYEE WHERE EMP_ID = 1; Output: NAME ParbhjotNAME Parbhjot   Next Topic: SQL WHERE Clause … Read more

Categories SQL