SQL Union syntax and instance
SQL Union allows you to combine the results of 2 or more personal queries. Unlike alliances, it is made by queries that are independent of each other's subqueries from. The Federation combines these individual selection outputs and lists them as part of a single output table.
SELECT column1, ... column_n
From derived_table
UNION [All]
SELECT column1, ... column_n
From derived_table
The SQL statements for each query must have the same number of results as the result of the field and similar data types. In addition, in the use of Federation, only a different value is selected (similar to selecting a different).
Instance One
SELECT Item
From Antiques
UNION
SELECT itemdesired
From Orders
In this example, if an item appears with two antique and orders tables, it will appear at your result set once.
Example Two
SELECT FirstName, LastName
From employeeaddresstable
WHERE City in (' Losantiville ', ' Paris ')
UNION SELECT Ownerfirstname,ownerlastname
From Antiqueowners
WHERE City in (' Losantiville ', ' Paris ', ' San Diego ')
========================
SQL JOIN statement Multi-table query
So far we've been looking for the query to retrieve the time from a single table of data. Single-table queries are useful, but they do not take advantage of the full functionality of the SQL language. SQL is a relational database tutorial query language, so one of its most important features is that it can retrieve information from several different related tables. In the case of a relational database, this process is called a connection. The table will be named to participate in the name of each table separated by a comma from the provisions of the Select section. Participates in the relationship between the tables defined by the WHERE clause predicate. Predicates can refer to any relationship from the form of a joined table column.
For example
SELECT Employeeaddresstable.employeeidno,
Employeeaddresstable.firstname,
Employeeaddresstable.lastname,
Employeestatisticstable.salary
From Employeeaddresstable, employeestatisticstable
WHERE Employeeaddresstable.employeeidno = Employeestatisticstable.employeeidno
The preceding example retrieves the number, first name, surname, and salary of the employee. From the Compensation Field connection table. This SQL statement will return all rows from the employeeaddresstable and employeestatisticstable tables. If there is a matching employeeidno either the employeeaddresstable and the Employeestatisticstable table value.
Added in
This is, in fact, the most common type of joining. The INNER join returns the condition from which all row joins from multiple tables are satisfied. There must be a common field that matches the values with two tables. An inner join cannot be nested in a left or right join join.
SELECT Employeeaddresstable.employeeidno,
Employeeaddresstable.firstname,
Employeeaddresstable.lastname,
Employeestatisticstable.salary
From employeeaddresstable INNER JOIN employeestatisticstable
On employeeaddresstable.employeeidno = Employeestatisticstable.employeeidno
With an inner JOIN operation, any relational comparison operator can be used on the ON clause: =, ",", "=," =, or "<". The example above returns the field value of the ' employeestatisticstable ' table that matches the ' employee ID ' of the ' employees ' table in all cases EmployeeID '. If there are no employeestatisticstable matches in the employeeaddresstable line, these lines will not be listed.
Left Join
The left JOIN operator is used to create a left outer join, including the two tables from the first (all records on the left), even if there is no matching second record value.
SELECT Employeeaddresstable.employeeidno,
Employeeaddresstable.firstname,
Employeeaddresstable.lastname,
Employeestatisticstable.salary
From employeestatisticstable left JOIN employeeaddresstable
On employeeaddresstable.employeeidno = Employeestatisticstable.employeeidno
This SQL statement returns all rows from the first table (employeestatisticstable), even if there is a second table (employeeaddresstable) mismatch. If there is no employeeaddresstable competition in employeestatisticstable, these lines will also be listed. In the result set, they will appear as.
Right Join
The right to join the operator is used to create a good outer join, including all by the second (right record two tables), even if there is no match in the first record value.
SELECT Employeeaddresstable.employeeidno,
Employeeaddresstable.firstname,
Employeeaddresstable.lastname,
Employeestatisticstable.salary
From employeestatisticstable right JOIN employeeaddresstable
On employeeaddresstable.employeeidno = Employeestatisticstable.employeeidno