SQL UNION Operators - Steem Alliance Community.

in Steem Alliance7 months ago

Hello Everyone,


Blue & White Futuristic Gaming Youtube Thumbnail_20240227_162635_0000.png

Good evening everyone, how are you, i hope you all guys will happy and good. By the grace of God, i am also good. Today i am here with new post in which we discuss the SQL Union operators. There are two types of operator. One is simple UNION and second is UNION ALL. we will also explore its syntax by using simple example.

In the field of database, SQL play an crucial role in manipulating data. The UNION operator is used for combining the results of multiple SELECT statements into a single result. by using UNION operators, data will increased by rows wise.

It removes duplicate rows automatically and provide the data set ideal. Some important rules are needed to follow for joins. The columns in each SELECT statement must have the same data types and same numbers of columns in corresponding positions.

UNION Syntax

SELECT column1, column2
FROM table1
UNION
SELECT column1, column2
FROM table2

The SQL UNION operator is vital for combining and aggregating data from various sources in a database. Knowing its syntax, features, and best practices empowers professionals to streamline data tasks, improving database efficiency.

User1

NOsectorname_1
11000ALI HAMZA
21000IMRAN
31000SIKANDAR

User2

NOsectorname_1
415Mustafa
5106Farhan
690abdullah

The above are two table on which we will apply the SQL UNION then see the result.

Select * from User1
Union
Select * from User2



See the below Result

NOsectorname_1
11000ALI HAMZA
21000IMRAN
31000SIKANDAR
415Mustafa
5106Farhan
690abdullah

images (9).png
Img Src

If we face the data requirement in which we need to make data set will allowing the duplication in data then we will use the UNION ALL operator.

We can also use the union and union all operators by using with clause. We can apply the filter on each select queries to get the data according to requirement.

For example i want to get those data that just have sector 1000 and sector 15 then we will apply the where clause on both tables then use the union operator to show and get the combine results. Below is the query that will meet our requirements.

Select * from User1 
where sector in (1000 , 15)
Union
Select * from User2 
where sector in (1000 , 15)

Now see the result.

NOsectorname_1
11000ALI HAMZA
21000IMRAN
31000SIKANDAR
415Mustafa

It would be my pleasure if you will share your opinion and reviews on this topic

20230310_190323_0000.png

Please cast witness vote to @bangla.Witness or set proxy to @rme.

_
Vote @bangla.witness as witness
Set Proxy @rme as proxy

Special Thanks.

Cc: @rme
Cc: @hungry-griffin
Cc: @pennsif

Thanks for giving your precious time to my post.
Follow | Upvote | Share | Comments
Follow me on Instagram.
Instagram

🆃🅷🅰️🅽🅺 🆈🅾️🆄

Sort:  

Congratulations, your post has been upvoted by @dsc-r2cornell, which is the curating account for @R2cornell's Discord Community.

Manually curated by @jasonmunapasee

r2cornell_curation_banner.png

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 59789.86
ETH 2418.86
USDT 1.00
SBD 2.43