UNION ALL operator example to fetch the single fieldįor this example, let us again create a table named Employee as Person with a field in common with identical data types to perform the UNION ALL query. Here, we have simultaneously used similar values from Person_Address and City columns from the Person and Customer tables. It is clear from the results that with the UNION operator, we have received the discrete values, and with UNION ALL operator, we have valued having identical rows. We are writing the following code executing the UNION operator to fetch the city address values from both tables, which are distinct rows in the result combined set:Īlso, let us execute the query above with the UNION ALL operator, which provides the resultant table which contains a combination of column values from both tables: Suppose we have entered some records as samples for the tables Person and Customer with the help of the MySQL query statements below, respectively:Ĭode: INSERT INTO Person('Person_ID', 'Person_Name', 'Person_Address') VALUES ('101','Akash','Delhi') We will perform the following SQL queries to create database tables for demonstrating the examples:Ĭode: CREATE TABLE Person(Person_ID INT PRIMARY KEY AUTO_INCREMENT, Person_Name VARCHAR(255) NOT NULL, Person_Address VARCHAR(255) NOT NULL) ĬREATE TABLE Customer(CustomerID INT PRIMARY KEY AUTO_INCREMENT, CustomerName VARCHAR(255) NOT NULL, Credit_Limit DECIMAL(10,2) NOT NULL, City VARCHAR(255) NOT NULL) First, we will create a table Person with fields Person_ID, Person_Name, and Person_Address and again create a second table Customer with fields CustomerID, CustomerName, Credit_Limit, and City. Let us consider two tables for implementing the query statements using both operators. Let us evaluate and illustrate some of the examples showing the working and results of the MySQL UNION ALL operator in the database upon the related tables: In that case, the result rows are retrieved but comprise duplicate row values between the several SELECT statements used in the command to make a union set of database tables. Suppose everything is proper in the UNION ALL query statement.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |