Union ALL in MySQL
MySQL Union ALL operation is used to combine two or more result sets. Before you use UNION ALL operator in MySQL or MariaDB, you need to remember couple of things.
UNION ALL will return Duplicate records if result sets have same records.
- When you combine two or more result sets, all the result sets should have the same number of columns.
- The data type of the columns of each result set should be compatible or same like other results set columns.
Syntax :
Union ALL in MySQL syntax
Select Column1,Column2,Column2 from TableOne
UNION ALL
Select Column1,Column2,Column3 from TableTwo
UNION ALL
Select Column1,Column2,Column2 from TableThree
Example :
Let's create couple of tables by using below scripts and then we use Union ALL operator.
CREATE TABLE `customer` (
`idcustomer` int,
`firstname` varchar(50) NULL,
`lastname` varchar(30) NULL,
`age` int(11) DEFAULT NULL,
`phonenumber` char(11) DEFAULT NULL,
`dob` date DEFAULT NULL,
`gender` char(1) NOT NULL
) ;
insert into customer(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,'Raza','Ali',39,'505-4141969','1980-01-01','M'),
(2,'Aamir','Naz',39,'505-4141969','1980-01-01','M'),
(3,'Aamir','Shahzad',39,'505-4141900','1980-01-01','M'),
(4,'Aamir1','Shahzad',39,'505-4141900','1980-01-01','M'),
(5,'Robert','Ladson',69,'505-345900','1960-01-01','M');
create table customer4.
CREATE TABLE `customer4` (
`idcustomer` int,
`firstname` char(50) NULL,
`lastname` Nchar(30) NULL,
`age` int(3) DEFAULT NULL,
`phonenumber` char(11) DEFAULT NULL,
`dob` date DEFAULT NULL,
`gender` char(1) NOT NULL
) ;
insert into customer4(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,'Raza','Ali',39,'505-4141969','1980-01-01','M'),
(5,'Aamir','Naz',39,'505-4141969','1980-01-01','M')
Let UNION ALL combine the rows or customer and customer4 table.
select * from customer
UNION ALL
Select * from customer4;
CREATE TABLE `customer4` (
`idcustomer` int,
`firstname` char(50) NULL,
`lastname` Nchar(30) NULL,
`age` int(3) DEFAULT NULL,
`phonenumber` char(11) DEFAULT NULL,
`dob` date DEFAULT NULL,
`gender` char(1) NOT NULL
) ;
insert into customer4(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,'Raza','Ali',39,'505-4141969','1980-01-01','M'),
(5,'Aamir','Naz',39,'505-4141969','1980-01-01','M')
Let UNION ALL combine the rows or customer and customer4 table.
select * from customer
UNION ALL
Select * from customer4;
MySQL Union ALL operator
Notice that in customer and customer4 some of the columns have different data types but it worked in UNION ALL as the data types are compatible. Also duplicate records are returned as UNION ALL returns all records from each result set and does not remove duplicate.
it was amazing.
ReplyDeleteTo buy a second hand mobile is not easy when you have little money in your hand. So you can search in Quikads; a classified ads platform in Bangladesh.
Do you need Personal Finance?
ReplyDeleteBusiness Cash Finance?
Unsecured Finance
Fast and Simple Finance?
Quick Application Process?
Finance. Services Rendered include,
*Debt Consolidation Finance
*Business Finance Services
*Personal Finance services Help
contact us today and get the best lending service
personal cash business cash just email us below
Contact Us: financialserviceoffer876@gmail.com
call or add us on what's app +918929509036
Mua vé máy bay tại Aivivu, tham khảo
ReplyDeleteVé máy bay đi Mỹ
giá vé máy bay từ mỹ về vn
mở chuyến bay từ nhật về việt nam
vé máy bay từ đức về việt nam giá rẻ
thông tin chuyến bay từ canada về việt nam
gia ve may bay tu han quoc ve viet nam
danh sách khách sạn cách ly đà nẵng
chuyen bay chuyen gia
If you have a dream to cook for offset smokers like professionals, this review is especially for you. Each smoker listed is the Best competition offset smoker more info.
ReplyDeleteProper training of concealedcarrytrainingvideo, and safety is our utmost priority, which is why we only work with 100% certified firearms instructors to ensure that your time is well invested, and you emerge as a smarter and more responsible certified gun owner.
ReplyDeletePDF Contains Data Regarding the Last Year Public Paper 2023 of RBSE Arts Subjects, Commerce, RBSE 11th Science Question Paper 2023 In Hindi to Enable Easier Understanding Among Parents and Students Alike. RBSE 11th Model Paper 2023 RBSE Paper 2023 PDF Contains Information on the Mandatory Subjects as well as Optional Subjects.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIt's informative, engaging, and leaves a lasting impression.
ReplyDeleteafricansmag