HTML

Union Operator:
  • It is used to combine the result sets of two or more select statements.
  • It removes the duplicate values in the result sets.
  • For union you must have the same number of fields in the results sets with similar data types.
  • By default it will selects distinct records.
Syntax: select column_names from table 1
              union

             select column_names from table 2

Command:
Output:

Union with where condition
Output:
Union all:
  • It is used to combine the result sets of two or more select statements.
  • It will allow duplicate values.
  • for using union all you must have the same number of fields in the result sets and same number of datatypes.

Syntax: select column_names from table 1
              union all
             select column_names from table 2
Command:

Output:


Group By:

The group by statement is used with aggregate functions like count,max,min,sum,avg.

  • Group by statement is used with the select statement.
  • In the query group by clause is placed after the where clause
  • In the query group by clause is placed before the order by clause
Syntax: select column_names from table_name where condition group by column_names order by column_names
Command: on single field
Output:
Command: with multiple fields
Output:

Group By with having
Having:
  • It is used in the aggregate functions because the where keyword could not use with aggregate functions.
  • The where keyword is used to apply conditions on selected columns whereas the having clause is used to apply conditions on groups created by the group by clause.
Syntax: select column_names from table_name where condition group by column_names Having conditions order by column_names
Command:
Output:

Keywords in sql:
Add: Adds a column in an existing table.
Add Constraint: Adds a constraint after creating a table
Alter: It is used to adds,delete or modifies columns in a table,changes the datatype of the column
All: Returns true if all the subquery valules meets the condition
And:Returns if the condition is true.
Any: Returns true if any of the sub query values meets the condition.
As: Renames a column or a table.The scope is with in that query.
Asc: Sorts the values in ascending order
Backup Database: Creates a backup of an existing database.
Between:Selects values within a given range.
Case: Creates different outputs based on conditions.
Check: A constraint that limits the value that can be placed in a column.
Column: Changes the data type of a column or deletes a column in a table.
Constraint: Adds or deleres a constraint.
Create: Creates a database, index, table, view or a procedure
Database: Creates or deletes a databsae
Default: A constraint that provides a default value to a column
Delete: Delete rows from a table
Desc: sorts the values in descending order.
Distinct: Selects only distinct values.
Drop: Deletes a column, constraint, Database,table.
Exec: Executes a stored procedure.
Exists: Tests for the existence of any record in a sub query.
From: Specifies  which table to select or delete data from.
Group by: Groups the result sets.
Having: Used instead of where wit aggregate functions.
In: It is just like or operator.
Index: creates or deletes an index in a table.
Insert into: Insert new rows in a table.
Insert into select: Copies data from one table into another table.
Is null: Tests for empty values.
Is not null: Tests for non empty values.
Or: Returns true if one of the conditions is true.
Order By: Sorts the results in ascending or descending order.
Outer Join: Returns all rows when there is a match in either left table or right table.
Select: Selects data from a database.
Select Distinct: Selects only distinct(Different) values.
Select Into: copies data from one table into a new table.
Select Top: Specifies the number of records to return in the result set.
Set: Specifies which column and values should be updated in a table.
Table: Creates a table. or adds, deletes or modifies column in a table.
Top: Specifies the number of records to return the result set.
Truncate Table: Deletes the data inside the table, but not the table itself.
Union: Combines the result set of two or more select statements.
Union All: Combines the result set of two or more select statements.It will allow duplicate values.
Update: Updates existing rows in a table.
Values: Specifies the values of an insert into statement.
Where: It returns the results which are fulfill the condition