Posts

Showing posts from April 4, 2021

What is Self Join in SQL ?

Image
   In the previous section, we have discussed what is joining and its types , in this section we will discuss the rest of the types. Self-join in SQL: Sometime we need to retrieve rows of the same table by applying some constraints to its fields. In these types of cases, self-join is the best option. It is the type of join in which one table is joined with itself depending on some condition that is specified in WHERE CLAUSE, means that the rows of the same table are compared for generating results. So self-join is used to merge the rows of the same table by matching them. There might be an error while writing the Query of self-join if the user will use the same table name twice after FROM keyword, so for resolving that problem we can use the different Alias of the same table. Syntax of Self Join: SELECT   column_name(N) FROM   table1 T 1 ,  table1 T 2 WHERE   condition ; Here T1 and T2 are the aliases of table1. So suppose we have Students table. Example of Self-join:  For

Types of joins in SQL Equi and Non_Equi join

Image
  Types of Joins in SQL: As the starter of SQL when you will apply any query it has some limitation that the resultant table is generated from one table only but there is some situations arise in which we may have to retrieve data from multiple tables and in that case we will use JOIN operation. If we want to generate the joined table (which will be the resultant table) from row pairing then two tables must have columns with the same values. Joining is the process of combining rows from multiple tables. Through joining, we can generate a short-lived table with all accessed columns from multiple tables that are specified in join. So here we will discuss different types of joins in SQL. How can we perform SQL joins: For performing JOIN we can use more than one table name after FROM keyword. These are obviously the name of those tables from which we want to extract data. Both table names should be written by using a separator or comma between them. WHERE Clause is used to specify the

Operators in SQL: BETWEEN, LIKE, IN, IS NULL,NOT NULL

Image
  SQL Operators : There are different types of operators that can be used in SQL statements. These operators can be logical, Relational , ANY, ALL, IS_NULL, IS NOT NULL, LIKE, IN, and BETWEEN Operator. As we have discussed Relational and Logical Operators . Here we will discuss the rest of operators. BETWEEN Operator: This Operator is also called RANGE SEARCH CONDITION Operator because it is used to retrieve the range of data between two values. We can give specify the upper and lower bound of data in the condition and resultant data would be between these bounds. It is used with the WHERE Clause. Its negated version is NOT BETWEEN that inverse the results of BETWEEN Operator. Syntax Of BETWEEN Operator: SELECT   column_name FROM   table_name WHERE   column_name  BETWEEN   value 1   AND   value 2 ; Let suppose there is a “Student” TABLE. Example: So if we want to extract the data of those students who have got Marks between 60 and 90 the query will be. Result: This Oper