Trending February 2024 # Case Study: Union Pacific Keeps Data On Track # Suggested March 2024 # Top 6 Popular

You are reading the article Case Study: Union Pacific Keeps Data On Track updated in February 2024 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Case Study: Union Pacific Keeps Data On Track

Since its founding in the 1860s, at a time when America was rapidly expanding westward, the Union Pacific Railroad has criss-crossed the country with essentially the same mission — to haul goods and supplies from Point A to B.

But virtually all aspects of this old-line company have been transformed by the IT revolution. Nowhere is it seen more than in Union Pacific’s engineering department, where each day 4,000 workers monitor and manage upkeep on every inch of 33,500 miles of track, cataloging every curve degree and rail joint, plus every UP bridge, road crossing, signal, and rail yard in 27 western states. Another 800 field inspectors input data from hand and visual tests.

AT A GLANCE: Union Pacific Railroad

The company: Union Pacific Railroad, which generates $12 billion in annual revenue, operates 33,500 miles of track in 27 U.S. states, hauling coal, cars, and other commodities across the country.

The problem: The need for 4,000 field workers, managers and execs generating 10 gigabytes of track-maintenance data a day to access and analyze data residing on 25 separate databases.

The solution: Business intelligence software from nQuire Software, which helped the railroad create a Web-based, personalized “dashboard” of critical information.

But two years ago UP faced a problem. All of these data exist on 25 databases residing in software created by four different companies (Oracle, Teradata, IBM’s DB2 platform, and SQL Server), running on hardware built by four other companies (Sun, Hewlett-Packard, IBM, and NCR).

The goal: easily access and analyze disparate sets of data residing in multiple systems across the country. “All of this has to be brought together (to determine) where we’re going to spend money and where we’re going to do maintenance,” Holder says.

Instead, management wanted to leverage technology to create a Web-based “dashboard” of key information about the condition of the railroad. It had to be personalized to each user, no matter where they were in the field, and it also had to be easy enough to navigate from with a browser by thousands of workers with only basic IT skills.

About two years ago the company set out to find a solution to its business intelligence needs. It measured several reporting and online analytical processing tools on functional, architectural, performance, and total-cost-of-solutions benchmarks.

The solution UP chose: business intelligence software from nQuire Software Inc., a privately held Minnetonka, Minn., firm. The result: A Web-based system that let workers access the right information in the right format at the right time, no matter their location or IT proficiency.

In May 2000, Union Pacific implemented nQuire Suite to bring together data stored in numerous operations, transactional, and data warehouse systems. The Suite platform consists of three components:

nQuire Server, which reaches beyond the bounds of any single data store to unify information from multiple data sources in relational, host, and XML-based systems. It provides the analytical capabilities to derive intelligence from data.

nQuire Answers, the suite’s portal function, providing self-service access to real-time information over the Internet or intranet.

nQuire Delivers, which lets companies create “information insurance,” whereby any information-based problem can be detected and the right person notified via Web or wireless device.

UP execs say the decision to go with nQuire was easy. Within hours of being installed during the pilot phase, nQuire was up and running against multiple data sources and was used by several dozen end users. Within several months, more than 600 users were accessing 45 data sources and using 65 nQuire “subject areas” — simplified business views of physical data that shield the user from complex underlying data structures.

The end result: an easy-to-access source for real-time data on track conditions that can be queried in numerous ways to help workers and management make business decisions and plan projects.

“There are a ton of different ways you can slice and dice your report,” Holder says, adding that the solution can do in hours and days was used to take weeks and months to accomplish. The system is supported by fewer than five full-time administrators, far fewer than required by many other business intelligence packages.

How is the system used? Say managers want to take a snapshot of the condition of Union Pacific’s railroad in the southern region. Based on internal criteria, or “risk factors,” managers can query the system, create a list of the “worst” and “best” areas of track, and produce actionable data that can be used for planning maintenance programs and deploying resources.

Want to find the sections of rail with the most “curve wear” or “head wear,” two terms that describe the physical deterioration of iron rails? nQuire can search the databases and come up with a list based on a variety of criteria, such as rail location, degree of curve, when the rail was laid, the percentage of “head loss,” vertical wear of the tracks, and other benchmarks.

Currently, UP’s data sources include more than 25 separate databases residing in Oracle, Teradata, DB2 Mainframe, DB2 PE, XML, Microsoft Access, and SQL server. Regarding hardware, nQuire resides on a dual Pentium Hewlett Packard NetServer LC3 (2-400 Mhz) with 1Gb of RAM. Individual data sources reside in NT, UNIX, and mainframe systems.

Currently, 4,000 UP workers use the nQuire system, but that’s expected to grow to include the entire 50,000-plus member workforce of the Union Pacific, which has revenues of $12 billion.

The company did not disclose details on the cost to implement and run the system. However, UP is said to be realizing a return on its investment in technology through, among other things, its ability to better manage their stock or replacement track. With a budget of several hundred million dollars per year to replace old track, a savings of a few percent can add up to a substantial return. An nQuire official said UP was able to implement the system with what amounted to two full-time administrators.

Pricing for nQuire’s server implementation starts at $225,000, with addition licensing or subscription fees being charged on a per-user basis, according to a company official. The company, which was founded in 1997 and began selling product in 1999, counts among its customers the Royal Bank of Canada, that country’s largest bank, and Simon Property Group, a real estate investment trust that owns malls.

If the results are any indication, Union Pacific will be moving quickly to roll out nQuire across other business divisions. Says Holder, “nQuire’s capabilities are enabling us to positively impact operating efficiencies, improve our ability to exploit our information assets, and allow employees at all levels of the organization access to the information that they specifically require to do their job.”

You're reading Case Study: Union Pacific Keeps Data On Track

Case Study: Thalappakatti Digital Marketing Strategies [Pdf


The Dindigul Thalappakatti restaurant has been in business for over 20 years and has managed to keep up with the latest trends in food service.

The Story of Dindugul Thalappakatti

Over the years, the restaurant was called Anandha Vilas to Thalappakatti Biriyani. In Tamil, “Chellappa” means the traditional turban. From 1957 to 2009, Dindigul Thalappakatti only had a single outlet in Dindigul itself.

Thalappakatti is a restaurant company based in the Indian state of Tamil Nadu, specialising in biriyani. 

The first outlet opened there in 1957. Since then, the restaurant has operated 62 locations in India, seven of which are currently overseas.

The speciality of their brand with the biryani comprises a special blend of spices. A common type of short-grain seeraga samba rice, called Parakkum Situ and Kannivadi meat which comes from tender cattle, makes the taste distinctive. 

This rice, unlike basmati, has no unique taste of its own, so it completely absorbs the flavours of the spices.

This makes the customers repeatedly prefer Dindugal Thalappakatti.

Digital Marketing Strategies by Dindigul Thalappakatti Social Media Marketing Strategies & Case Study

A few important aspects must be considered to develop an efficient social media marketing plan. The social media sites used by your target audience must first be determined.

The next step is to produce shareable, amazing content that will appeal to your audience. It’s also essential to consider when and how frequently you should post.

A restaurant’s social media campaign should efficiently use video and photographs to pique people’s appetites.

1. Instagram Marketing Strategies of Dindigul Thalappakatti

A restaurant called Dindugal Thalappakatti is well-known for its fantastic food and outstanding service. 

Instagram user Dindugal Thalappakatti frequently posts mouthwatering images of their delectable cuisine and the restaurant’s lovely decor. 

Additionally, they skillfully employ hashtags to reach a larger audience.

Influencers from all over the world are vying for a spot to review Dindugal Thalappakatti on Instagram.

The official account of Dindugal Thalappakatti is Dindugal Thalappakattichettinaduoffical.

Dindugal Thallapakatti has an average of 1830 likes per day, 34,724 followers, and 1830 posts.

Building brand awareness on Instagram is not a concern for this well-known biryani vendor because Dindugal Thallapakatti has been around for a while.

Here is Dindugal Thalappakatti’s list of hashtags used for promoting his posts.

Here are Dindigul Thalappakatti’s top 10 hashtags for reaching out to his Instagram followers.

Above is Dindugal Thallapakatti’s most recently viewed Instagram post, which went viral.

2. Facebook Marketing Strategies of Dindigul Thalappakatti

The owners of Dindigul Thalappakatti started using Facebook to promote their business and reach out to their customers.

Over 41k people have liked Dindigul Thalappakatti’s Facebook page because of the results.

Their colour palettes are very appealing when viewed together.

Dindigul Thalappakatti’s Facebook Progress Graph & Case Study

Through social media, they also promote their business from the perspective of their customers.

A daily average of 250+ likes and 800 visitors is recorded for Dindigul Thalappakatti Chettinad Restaurant.

3. Twitter Marketing Strategies of Dindigul Thalappakatti

A large audience can be reached through Twitter, which has over 328 million monthly active users.

This one is Dindigul Thalappakatti’s only account aiming to gain more attention from worldwide audiences.

This tweet on Dindigul Thalappakatti has gone viral. In contrast to sites like Facebook and Instagram, Dindigul Thalappakatti does not appear to use any effective social media promotion on Twitter.

Dindigul Thalappakatti’s SEO Marketing Strategies

Due to its unique marketing strategies and focus on quality food and service, the restaurant has been successful.

Due to the food-based nature of its website, there is no obvious improvement in SEO strategies.

Therefore, let’s take a closer look at Dindigul Thalappakatti’s SEO strategies.

There are only 2.1k backlinks on the Dindigul Thalappakatti website, which has an impression of 162.7k organic traffic.

Dindigul Thalappakatti has an Authority Score of 38 with organic search traffic of 162.7k through the 2.1k backlinks.

An SEO tool called Moz determines a website’s domain authority based on multiple factors, including backlinks, site consistency, page load time, traffic, and the average time visitors spend on each page.

The Domain Authority rating of Dindigul Thalappakatti’s website is 28, according to Moz. However, this score might go up in the future.

Additionally, Dindigul Thalappakatti has 162.7k traffic for inserting the right keywords (11.7k) on their site.

Their top organic keywords are Thalappakatti, Dindigul Thalappakatti Hotel, Thalappakatti Biriyani, and Chettinad Dindigul Thalappakatti.

It shows how good Dindugal Thallapakatti’s branding and local SEO is that 18% of their traffic comes from local keywords like “Thalappakatti Biryani”.

Unfortunately, we do not find any business keywords in their top 10 keywords. There are a lot of keyword opportunities they are missing. 

However, The upcoming years will be great for them to revamp their SEO strategies.

Who are the competitors for Dindigul Thalappakatti?

The main organic competitor is Dindugal. 

Types of SEO Targeting Audience for Dindigul Thalappakatti

With 304 keywords on their website, they gain 148 traffic, with their informational keyword reaching 32.4k% of the audience.

Dindigul Thalappakatti’s Main Competitors

With higher SE keywords, Dindigul Thalapakattii’s top three competitors are chúng tôi chúng tôi and

To get a better idea of where Dindugal Thalappakatti stands, take a look at its competitors.

Dindigul Thalappakatti’s Target Segment

SegmentTargetAge18-50CuisineChettinad cuisineFood TypeVeg, Non- vegBranches70+ branches includes India, United Arab Emirates, Qatar, Kuwait, chúng tôi Selling ProductBriyaniSpecial AudienceChildren- introduced special “DT Joybox”

What Product did Dindigul Thalappakatti sell?

A chain of eateries known as Dindugal Thalapakatti specialises is Chettinad cuisine, a style of Tamil Nadu cuisine.

In addition to having restaurants in the United Arab Emirates, Qatar, Kuwait, and Oman, Dindugal Thallapakatti has over 70 branches throughout India.

There are both vegetarian and non-vegetarian options on the menu at Dindigul Thalappakatti.

Among the many dishes offered by Dindigul Thalappakatti, Briyani is one of the audience’s most popular and best-searched products.

Dindigul Thalappakatti Price and Offers

Dindigul Thallapakatti’s website has a rate chart based on the revisions they offer. By knowing their price and cost, you can make an informed decision.

Dindigul Thalappakatti Geo-Targeting Audiences

Dindigul Thalappakatti offers the following packages to its clients.

There is a strong motivation for coverage among those between the ages of 18 and 50.

Dindugal Thalappakatti prefers males over females when it comes to gender. The total audience value of their audience is 5.8k.

But they do not miss to target the audience who always craves tasty food, but the parents prefer healthy food for them. As Thalappakatti serves a combination of both, children are their perfect audience. They offer a special platter for children as “DT Joybox.”

Influencer Marketing Campaign by Dindigul Thalappakatti

Dindugal Thallapakatti is using many influencers to promote their business to Instagram followers.

For example, @f.o.o.d.t.h.e.r.p.y frequently promotes Dindigul Thalappakatti on their page to attract audiences’ attention.

Mobile App Marketing Strategies of Dindigul Thalappakatti

In light of Dindigul Thallapakatti’s app, it is essential that the developers he assigned fix the bug and build a positive rapport with the target market.

Campaign Strategies: Dindigul Thalappakatti #DT Daily Sooper Meals

Targeting all sort of audience, and showing big savings, Dindigul Thalappakatti restaurant launched its sooper meals combo for Veg & non-veg.

This was the recent campaign done by Dindigul Thalappakatti, with the meals served at @1149/-

Dindigul Thalappakatti Hotels Career Opportunities

Dindigul Thalappakatti Hotels has over 70 branches worldwide, they are contributing in employment generation as well. Time to time there are multiple career opportunities available in Thalappakatti restaurant chain.

You can go to career on the website to check on or jump on to the LinkedIn profile for the recent openings.


According to a recent assessment of Dindigul Thalappakatti’s digital marketing strategies by Digital Scholar, Dindugal Thalappakatti has successfully handled several digital marketing strategies.

If you have difficulty understanding the concepts and marketing assessments represented in this case study, you should enrol in a digital marketing course to gain more expertise in the field.

About Digital Scholar

The brand-new digital course from Digital Scholar is intended for experts and newbies who want to establish and maintain a successful online presence.

The course covers all the fundamentals of online marketing, including creating successful social media campaigns and planning and constructing your website.

You can work in your comfort zone and complete the course in 4 months because it is presented in self-paced agency-style learning.

Additionally, suppose you’re a professional or student who wants to master To learn digital marketing in person. In that case, our digital scholar is ready to greet you with a four-month offline course.

Join our free digital marketing course with 20+ free modules now before it ends with receiving a free online digital marketing certification!

Case Study: Amazon’S Digital Marketing Strategies [Pdf

It all started with a single book. In the early days of the internet, Amazon was nothing more than an online bookstore. But Jeff Bezos, the company’s founder, had a vision for something much bigger. He wanted Amazon to be the everything store, a one-stop shop for anything and everything people might want.

In order to make this vision a reality, Amazon needed to expand into new markets. And so, in the late 1990s, it set its sights on India.

About Amazon

Amazon was founded in 1994 by Jeff Bezos. The company started as an online bookstore and has since expanded to sell various items, including electronics, furniture, apparel, and food.

Amazon has become one of the largest retailers in the world, with sales totalling over $100 billion in 2024. The company has also been diversifying its business, with ventures into cloud computing, streaming video, and artificial intelligence.

Since 2023, Andrew R. Jassy, an American business entrepreneur born on January 13, 1968, has served as the president and CEO of Amazon.

From 2003 to 2023, he served as senior vice president and CEO of Amazon Web Services. Jeff Bezos chose him during the fourth quarter of 2023, when Bezos assumed the executive chairman role.

Why Should Digital Marketers Study Amazon’s Digital Marketing Strategies? 

Amazon’s digital marketing strategies have played a big role in the company’s success in India.

One of the key elements of Amazon’s digital marketing strategy is its focus on customer experience. Amazon has always been focused on providing the best possible customer experience, and this is evident in the company’s Indian operations. Amazon has invested heavily in infrastructure and logistics in order to ensure that its customers receive their orders on time and in good condition. The company has also developed a strong customer service operation in India, which has helped it build a loyal customer base.

Another important aspect of Amazon’s digital marketing strategy is its use of data. Amazon has a huge database of customer data that it can use to segment its audience and create targeted marketing campaigns. This data allows them to personalize their marketing messages and offer products that are relevant to their customers. Amazon also uses data to optimize their website and make sure that their customers have a positive experience. 

Amazon Logo

Amazon is a company that has evolved greatly over the years, and its logo is a perfect reflection of that journey. From a small online retailer to one of the world’s largest businesses, Amazon has made its mark in nearly every sector of the market.

You can see the development in the marketing strategies of Amazon in the logo itself. See if your design can keep up with the world’s largest retailer!

Amazon’s Digital Marketing Strategies 

Amazon is always testing and tweaking its strategies in order to ensure that they are providing the best possible experience for its customers. In order to satisfy its customers & fulfill all the demands Amazon always comes up with great marketing strategies.

And, to give easy access to customers amazon designed fully SEO optimized website that is accepted by its millions of customers.

Below, we have discussed the different digital marketing strategies they employed that marketers can learn from.

Amazon’s Social Media Marketing Strategies & Case Study

Amazon uses social media activities to promote their products, generate brand awareness and connect with their audience. Let’s discuss Amazon’s strategies on each of these platforms. 

Amazon’s Instagram Marketing Strategies

Amazon India’s Instagram page (amazondotin), has over 2.2 million followers as of November 2023. Their content on Instagram is notably tailored to the page and makes posts that are focused on visuals and engagement. 

Most of their posts are engagement-focused. For instance, you can see in this post below where Amazon is urging their followers to screenshot an outfit. Through this, customers spend more time on the respective post. 

Next, you’ll also notice many product-based posts that update their customers with different and ongoing offers. This generates sales for their brand and creates urgency. 

The third type of post that you can find on Amazon’s Instagram page is collaborations with influencers. 

Amazon’s Facebook Marketing Strategies

Amazon’s main Facebook account has over 1million of followers, and is mostly used to sell products, highlight offers, run competitions, publish community content, and communicate noteworthy posts. These are frequently optimised to coincide with key events and holidays, giving clients attractive and valuable content.

Amazon Case Study- Facebook Stas

Amazon India’s Facebook progress graph shows the data how people are talking about Amazon offers on the facebook over the past year.

Amazon’s Twitter Marketing Strategies

Amazon knows how to do Twitter marketing right and holds over a 2.4million followers on the platform.

Here are 3 key strategies they use to drive results using Twitter marketing.

They create engaging content that resonates with their target audience

They use Twitter Analytics to track their results and optimize their campaigns

Amazon never misses any updates to go on their Twitter handle & create a buzz.

Amazon’s Email Marketing Strategies

We receive emails from Amazon praising us for signup up in the welcome mail, for our purchase, shipping of the product, delivery confirmation, asking for a product review, and even providing a discount if we provide our email address. This is known as email marketing.

Amazon shipping confirmation emailAmazon welcome email

Amazon’s email marketing strategy is straightforward it sends customized product recommendation emails to customers based on factors such as purchase history, past order value, location, age, gender, and on-site browsing.

Amazon’s Youtube Marketing Strategies

The youtube analytical data for Amazon clearly shows their youtube marketing strategy and the rise in the number of video views of the channel. They pretty much gain a good number of subscribers every month. Amazon has more than 1.44 million youtube subscribers as of November 2023.

Amazon’s SEO strategies Website

Amazon has a highly functional website which has a high domain authority of 92. They are ranked “amazing” in all four website factors taken into consideration by Amazon, which are organic keywords (14,009,442), organic monthly traffic (412,258,825), domain authority (92), and backlinks (157,932,667). 

Mobile Marketing

The amazon apps are available across all major platforms, including iOS, Android, and Windows Phone.

They have every 10 million Android installs with a 4.1 rating, increasing the amount of app-specific offers to boost app popularity. They also ensure to provide ongoing updates on their existing app.

Amazon’s Target Audience

Amazon’s target audience comes from all walks of life, including students and professionals, singles and families, and low to high-income.

Amazon offers everything you could ask for, from electronics to clothing to home goods. Students can find textbooks for their classes and the latest in technological accessories. Professionals can find anything from business clothes to home office supplies and furniture. Singles and families can find outfits for both works and play and home goods to furnish a new apartment or to spruce up an old one. Amazon has something for all people.

What is also worth noting is that Amazon also sells to people living in rural areas, a segment that is often overlooked.

Amazon’s Top Digital Marketing Campaigns  1. The Great Indian Shopping Festival 

Every year, Amazon hosts the great Indian shopping festival, reaches new openings, and hits new records. In fact, according to a report by Live Mint, Amazon increased their sales by 8x during the festival in 2023! 

‘Ab India ki khushiyon ke beech budget nahi aayega!’ claims Amazon India. (Your happiness will no longer be limited by your budget.) The organisation goes above and beyond to entice everyone to its offerings and facilities.

Amazon India’s main film created for the event depicts the same tale of an Indian Parivar- how they prepare to purchase clothes, jewellery, and more without being restricted to any pre-equipped budget through Amazon.

2. #AurDikhao

The very successful Aur Dikhao campaign debuted in 2024 with the goal of emphasizing the wide range of products available on chúng tôi The colloquial expression ‘AurDikhao,’ which accurately portrays India’s collective enthusiasm for diversity in shopping, was well received by the crowd.

To this day, the primary source of information for Indians is word of mouth from friends and relatives. The new ad features a delightful interaction between family members while making an online purchase, as well as how one person may assist the other in locating the correct product and payment choice. The campaign communicates the several benefits that Indian consumers want when buying, such as a wide range of brands, various ways of payment, and the simplicity of easy returns.

3. #DeliverThanks – A UGC campaign

User-generated campaigns are one of the most effective digital marketing campaigns. If successful, it can do wonders for your brand. Amazon India introduced the second edition of its digital campaign ‘#DeliverThanks,’ which encourages consumers to convey messages of happiness and appreciation for its frontline staff that assure safe and timely delivery of their ‘Khushiyon ke dibbe.’ 

The ad aims to acknowledge the efforts of tens of thousands of associates across Amazon’s Operations Network. They work tirelessly to guarantee that customers’ holiday shopping arrives safely and on schedule every time. The second edition of #DeliverThanks encourages customers to get creative and leave a ‘Thank You’ letter or poster on their doorstep for delivery workers, who will be thrilled and grateful when they arrive at the customer’s house for delivery. They also encouraged users to share the thank you note on their social media platforms.


As you can see, Amazon has a website to promote its items and brand. Do you want to make equally successful plans? Enrol in Digital Scholar’s online digital marketing course to learn how to create effective digital marketing strategies for your business.

Are you willing to help your company’s reputation? Now is an excellent time to begin an online digital marketing program!

Which Amazon marketing campaign do you prefer? Fill out the form below with your feedback.

Knowledge Distillation: Theory And End To End Case Study

This article was published as a part of the Data Science Blogathon

on a business problem to classify x-ray images for pneumonia detection.

Image Source: Alpha Coders

What is Knowledge Distillation?

Knowledge Distillation aims to transfer knowledge from a large deep learning model to a small deep learning model. Here size is in the context of the number of parameters present in the model which directly relates to the latency of the model.

Knowledge distillation is therefore a method to compress the model while maintaining accuracy. Here the bigger network which gives the knowledge is called a Teacher Network and the smaller network which is receiving the knowledge is called a Student Network.

 (Image Source: Author, Inspired from Reference [6])

Why make the Model Lighter?

In many applications, the model needs to be deployed on systems that have low computational power such as mobile devices, edge devices. For example, in the medical field, limited computation power systems (example: POCUS – Point of Care Ultrasound) are used in remote areas where it is required to run the models in real-time. From both time(latency) and memory (computation power) it is desirable to have ultra-lite and accurate deep learning models.

But ultra-lite (a few thousand parameters) models may not give us good accuracy. This is where we utilize Knowledge Distillation, taking help from the teacher network. It basically makes the model lite while maintaining accuracy.

Knowledge Distillation Steps

Below are the steps for Knowledge distillation:

3) Train the student network intelligently in coordination with the teacher network: The student network is trained in coordination with the fully trained teacher network. Here forward propagation is done on both teacher and student networks and backpropagation is done on the student network. There are two loss functions defined. One is student loss and distillation loss function. These loss functions are explained in the next paragraph of this article.


Knowledge Distillation Mathematical Equations:

(Image Source: Author, Inspired from Reference [7])

Loss Functions for teacher and student networks are defined as below:

Teacher Loss LT: (between actual lables and predictions by teacher network)

LT = H(p,qT)

Total Student Loss LTS :

LTS =  α * Student Loss + Distallation Loss

LTS =  α* H(p,qs) + H(q̃T, q̃S) 


Distillation Loss = H(

q̃T, q̃S


Student Loss = H(p,qS)



: Loss function (Categorical Cross Entropy or KL Divergence)



and z


: pre-softmax logits

q̃T : softmax(zT/t)

q̃S: softmax(zS/t)

alpha (α) and temperature (t) are hyperparameters.

Temperature t is used to reduce the magnitude difference among the class likelihood values.

These mathematical equations are taken from reference [3].

End to End Case Study

Here we will look at a case study where we will implement the knowledge distillation concept in an image classification problem for pneumonia detection.

About Data:

The dataset contains chest x-ray images. Each image can belong to one of three classes:



Let’s get started!!

Importing Required Libraries:

import numpy as np import matplotlib.pyplot as plt import os import pandas as pd import glob import shutil import tensorflow as tf from tensorflow.keras.models import Model from tensorflow.keras.layers import Conv2D, Dropout, MaxPool2D, BatchNormalization, Input, Conv2DTranspose, Concatenate from tensorflow.keras.losses import SparseCategoricalCrossentropy, CategoricalCrossentropy from tensorflow.keras.optimizers import Adam from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint import matplotlib.pyplot as plt from tensorflow.keras.preprocessing.image import ImageDataGenerator import cv2 from sklearn.model_selection import train_test_split import random import h5py from IPython.display import display from PIL import Image as im import datetime import random from tensorflow.keras import layers

Downloading the data

The data set is huge. I have randomly selected 1000 images for each class and kept 800 images in train data, 100 images in the validation data, and 100 images in test data for each of the classes. I had zipped this and uploaded this selected data into my google drive.

S. No. Class Train Test Validation

1. Normal 800 800 800

2. BACTERIA 100 100 100

3. VIRUS 100 100 100

Downloading the data from google drive to google colab:

#downloading the data and unzipping it from google.colab import drive drive.mount('/content/drive') !unzip "/content/drive/MyDrive/" -d "/content/"

Visualizing the images

We will now look at some images from each of the classes.

for i, folder in enumerate(os.listdir(train_path)): for j, img in enumerate(os.listdir(train_path+"/"+folder)): filename = train_path+"/"+folder + "/" + img img= ax = plt.subplot(3,4,4*i+j+1) ax.set_xlabel(folder+ ' '+ str(img.size[0]) +'x'+ str(img.size[1])) plt.imshow(img, 'gray') ax.set_xlabel(folder+ ' '+ str(img.size[0]) +'x'+ str(img.size[1])) ax.axes.xaxis.set_ticklabels([]) ax.axes.yaxis.set_ticklabels([]) #plt.axis('off') img.close() break

So above sample images suggest that each x-ray image can be of a different size.

Creating Data Generators

We will use Keras ImageDataGenerator for image augmentation. Image augmentation is a tool to get multiple transformed copies of an image. These transformations can be cropping, rotating, flipping. This helps in generalizing the model. This will also ensure that we get the same size (224×224) for each image. Below are the codes for train and validation data generators.

def trainGenerator(batch_size, train_path): datagen = ImageDataGenerator(rescale=1. / 255, rotation_range=5, shear_range=0.02, zoom_range=0.1, brightness_range=[0.7,1.3], horizontal_flip=True, vertical_flip=True, fill_mode='nearest') train_gen = datagen.flow_from_directory(train_path, batch_size=batch_size,target_size=(224, 224), shuffle=True, seed=1, class_mode="categorical" ) for image, label in train_gen: yield (image, label)

def validGenerator(batch_size, valid_path):

datagen = ImageDataGenerator(rescale=1. / 255, )

valid_gen = datagen.flow_from_directory(valid_path, batch_size=batch_size, target_size=(224, 224),shuffle=True, seed=1 )

for image, label in valid_gen:

yield (image, label)

Model 1: Teacher Network

Here we will use the VGG16 model and train it using transfer learning (based on the ImageNet dataset).

We will first define the VGG16 model.

from tensorflow.keras.applications.vgg16 import VGG16

base_model = VGG16(input_shape = (224, 224, 3), # Shape of our images

weights = ‘imagenet’)

Out of the total layers, We will make the first 8 layers untrainable:


for layer in base_model.layers[:8]:

layer.trainable = False

x = layers.Flatten()(base_model.output) # Add a fully connected layer with 512 hidden units and ReLU activation x = layers.Dense(512, activation='relu')(x) #x = layers.BatchNormalization()(x) # Add a dropout rate of 0.5 x = layers.Dropout(0.5)(x) x = layers.Dense(3)(x) #linear activation to get pre-soft logits model = tf.keras.models.Model(base_model.input, x) opti = Adam(learning_rate=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.001) model.summary()

As we can see, there are 27M parameters in the teacher network.

One important point to note here is that the last layer of the model does not have any activation function (i.e. it has default linear activation). Generally, there would be a softmax activation function in the last layer as this is a multi-class classification problem but here we are using the default linear activation function to get pre-softmax logits. Because these pre-softmax logits will be used along with the student network’s pre-softmax logits in the distillation loss function.

Hence, we are using from_logits = True in the CategoricalCrossEntropy loss function. This means that the loss function will calculate the loss directly from the logits. If we had used softmax activation, then it would have been from_logits = False.

We will now define a callback for the early stopping of the model and run the model.

Running the model:

earlystop = EarlyStopping(monitor='val_acc', patience=5, verbose=1) filepath="model_save/weights-{epoch:02d}-{val_accuracy:.4f}.hdf5" checkpoint = ModelCheckpoint(filepath=filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max') callbacks = [earlystop ] vgg_hist =, validation_data = validation_generator, validation_steps=10, steps_per_epoch = 90, epochs = 50, callbacks=callbacks)

Checking the accuracy and loss for each epoch:

import matplotlib.pyplot as plt plt.figure(1) # summarize history for accuracy plt.subplot(211) plt.plot(vgg_hist.history['acc']) plt.plot(vgg_hist.history['val_acc']) plt.title('teacher model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'valid'], loc='lower right') # summarize history for loss plt.subplot(212) plt.plot(vgg_hist.history['loss']) plt.plot(vgg_hist.history['val_loss']) plt.title('teacher model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'valid'], loc='upper right')

Now we will evaluate the model on the test data:

# First, we are going to load the file names and their respective target labels into a numpy array!

from sklearn.datasets import load_files import numpy as np test_dir = '/content/test' def load_dataset(path): data = load_files(path) files = np.array(data['filenames']) targets = np.array(data['target']) target_labels = np.array(data['target_names']) return files,targets,target_labels x_test, y_test,target_labels = load_dataset(test_dir) from keras.utils import np_utils y_test = np_utils.to_categorical(y_test,no_of_classes) # We just have the file names in the x set. Let's load the images and convert them into array. from keras.preprocessing.image import array_to_img, img_to_array, load_img def convert_image_to_array(files): images_as_array=[] for file in files: # Convert to Numpy Array images_as_array.append(tf.image.resize(img_to_array(load_img(file)), (224, 224))) return images_as_array x_test = np.array(convert_image_to_array(x_test)) print('Test set shape : ',x_test.shape) x_test = x_test.astype('float32')/255 # Let's visualize test prediction. y_pred_logits = model.predict(x_test) y_pred = tf.nn.softmax(y_pred_logits) # plot a raandom sample of test images, their predicted labels, and ground truth fig = plt.figure(figsize=(16, 9)) for i, idx in enumerate(np.random.choice(x_test.shape[0], size=16, replace=False)): ax = fig.add_subplot(4, 4, i + 1, xticks=[], yticks=[]) ax.imshow(np.squeeze(x_test[idx])) pred_idx = np.argmax(y_pred[idx]) true_idx = np.argmax(y_test[idx]) ax.set_title("{} ({})".format(target_labels[pred_idx], target_labels[true_idx]), color=("green" if pred_idx == true_idx else "red"))

Calculating the accuracy of the test dataset:

print(model.metrics_names)  loss, acc = model.evaluate(x_test, y_test, verbose = 1) print('test loss = ', loss)  print('test accuracy = ',acc)


Model 2 –S

The student network defined here has a series of 2D convolutions and max-pooling layers just like our teacher network VGG16. The only difference is that number of Convolutions filters in the student network is very less in each layer as compared to the teacher network. This would make us achieve our goal to have a very less number of weights (parameters) to be learned in the student network during training.

Defining the student network:

# import necessary layers  

from tensorflow.keras.layers import Input, Conv2D 

from tensorflow.keras.layers import MaxPool2D, Flatten, Dense, Dropout from tensorflow.keras import Model # input input = Input(shape =(224,224,3)) # 1st Conv Block x = Conv2D (filters =8, kernel_size =3, padding ='valid', activation='relu')(input) x = Conv2D (filters =8, kernel_size =3, padding ='valid', activation='relu')(x) x = MaxPool2D(pool_size =2, strides =2, padding ='valid')(x) # 2nd Conv Block x = Conv2D (filters =16, kernel_size =3, padding ='valid', activation='relu')(x) x = Conv2D (filters =16, kernel_size =3, padding ='valid', activation='relu')(x) x = MaxPool2D(pool_size =2, strides =2, padding ='valid')(x) # 3rd Conv block x = Conv2D (filters =32, kernel_size =3, padding ='valid', activation='relu')(x) x = Conv2D (filters =32, kernel_size =3, padding ='valid', activation='relu')(x) #x = Conv2D (filters =32, kernel_size =3, padding ='valid', activation='relu')(x) x = MaxPool2D(pool_size =2, strides =2, padding ='valid')(x) # 4th Conv block x = Conv2D (filters =64, kernel_size =3, padding ='valid', activation='relu')(x) x = Conv2D (filters =64, kernel_size =3, padding ='valid', activation='relu')(x) #x = Conv2D (filters =64, kernel_size =3, padding ='valid', activation='relu')(x) x = MaxPool2D(pool_size =2, strides =2, padding ='valid')(x) # 5th Conv block x = Conv2D (filters =64, kernel_size =3, padding ='valid', activation='relu')(x) x = Conv2D (filters =64, kernel_size =3, padding ='valid', activation='relu')(x) #x = Conv2D (filters =64, kernel_size =3, padding ='valid', activation='relu')(x) x = MaxPool2D(pool_size =2, strides =2, padding ='valid')(x) # Fully connected layers x = Flatten()(x) #x = Dense(units = 1028, activation ='relu')(x) x = Dense(units = 256, activation ='relu')(x) x = Dropout(0.5)(x) output = Dense(units = 3)(x) #last layer with linear activation # creating the model s_model_1 = Model (inputs=input, outputs =output) s_model_1.summary()

Note that the number of parameters here is only 296k as compared to what we got in the teacher network (27M).

Now we will define the distiller. Distiller is a custom class that we will define in Keras in order to establish coordination/communication with the teacher network.

This Distiller Class takes student-teacher networks, hyperparameters (alpha and temperature as mentioned in the first part of this article), and the train data (x,y) as input. The Distiller Class does forward propagation of teacher and student networks and calculates both the losses: Student Loss and Distillation Loss. Then the backpropagation of the student network is done and weights are updated.

Defining the Distiller:

class Distiller(keras.Model): def __init__(self, student, teacher): super(Distiller, self).__init__() self.teacher = teacher self.student = student def compile( self, optimizer, metrics, student_loss_fn, distillation_loss_fn, alpha=0.5, temperature=2, ): """ Configure the distiller. Args: optimizer: Keras optimizer for the student weights metrics: Keras metrics for evaluation student_loss_fn: Loss function of difference between student predictions and ground-truth distillation_loss_fn: Loss function of difference between soft student predictions and soft teacher predictions alpha: weight to student_loss_fn and 1-alpha to distillation_loss_fn temperature: Temperature for softening probability distributions. Larger temperature gives softer distributions. """ self.student_loss_fn = student_loss_fn self.distillation_loss_fn = distillation_loss_fn self.alpha = alpha self.temperature = temperature def train_step(self, data): # Unpack data x, y = data # Forward pass of teacher teacher_predictions = self.teacher(x, training=False) #model = ... # create the original model teacher_predictions = self.teacher(x, training=False) with tf.GradientTape() as tape: # Forward pass of student # Forward pass of student student_predictions = self.student(x, training=True) # Compute losses student_loss = self.student_loss_fn(y, student_predictions) distillation_loss = self.distillation_loss_fn( tf.nn.softmax(teacher_predictions / self.temperature, axis=1), tf.nn.softmax(student_predictions / self.temperature, axis=1), ) loss = self.alpha * student_loss + distillation_loss # Compute gradients trainable_vars = self.student.trainable_variables gradients = tape.gradient(loss, trainable_vars) # Update weights self.optimizer.apply_gradients(zip(gradients, trainable_vars)) # Update the metrics configured in `compile()`. # Return a dict of performance results = { m.result() for m in self.metrics} results.update( {"student_loss": student_loss, "distillation_loss": distillation_loss} ) return results def test_step(self, data): # Unpack the data x, y = data # Compute predictions y_prediction = self.student(x, training=False) # Calculate the loss student_loss = self.student_loss_fn(y, y_prediction) # Update the metrics. # Return a dict of performance results = { m.result() for m in self.metrics} results.update({"student_loss": student_loss}) return results

Now we will initialize and compile the distiller. Here for the student loss, we are using the Categorical cross-entropy function and for distillation loss, we are using the KLDivergence loss function.

KLDivergence loss function is used to calculate the distance between two probability distributions. By minimizing the KLDivergence we are trying to make student network predict similar to teacher network.

Compiling and Running the Student Network Distiller:

# Initialize and compile distiller distiller = Distiller(student=s_model_1, teacher=model) optimizer=Adam(learning_rate=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.001), metrics=['acc'], student_loss_fn=CategoricalCrossentropy(from_logits=True), distillation_loss_fn=tf.keras.losses.KLDivergence(), alpha=0.5, temperature=2, ) # Distill teacher to student distiller_hist =, validation_data = validation_generator, epochs=50, validation_steps=10, steps_per_epoch = 90)

Checking the plot of accuracy and loss for each epoch:

import matplotlib.pyplot as plt plt.figure(1) # summarize history for accuracy plt.subplot(211) plt.plot(distiller_hist.history['acc']) plt.plot(distiller_hist.history['val_acc']) plt.title('model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'valid'], loc='lower right') # summarize history for loss plt.subplot(212) plt.plot(distiller_hist.history['student_loss']) plt.plot(distiller_hist.history['val_student_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'valid'], loc='upper right') plt.tight_layout()

Checking accuracy on the test data:

print(distiller.metrics_names) acc, loss = distiller.evaluate(x_test, y_test, verbose = 1) print('test loss = ', loss) print('test accuracy = ',acc)

We have got 74% accuracy on the test data. With the teacher network, we had got 77% accuracy. Now we will change the hyperparameter t, to see if we can improve the accuracy in the student network.

Compiling and Running the Distiller with t = 6:

# Initialize and compile distiller distiller = Distiller(student=s_model_1, teacher=model) optimizer=Adam(learning_rate=1e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.001), metrics=['acc'], student_loss_fn=CategoricalCrossentropy(from_logits=True), #distillation_loss_fn=CategoricalCrossentropy(), distillation_loss_fn=tf.keras.losses.KLDivergence(), alpha=0.5, temperature=6, ) # Distill teacher to student distiller_hist =, validation_data = validation_generator, epochs=50, validation_steps=10, steps_per_epoch = 90)

Plotting the loss and accuracy for each epoch:

import matplotlib.pyplot as plt plt.figure(1)

# summarize history for accuracy  




plt.title('model accuracy')  



plt.legend(['train', 'valid'], loc='lower right')  

 # summarize history for loss  




plt.title('model loss')  



plt.legend(['train', 'valid'], loc='upper right')


Checking the test accuracy:

print(distiller.metrics_names) acc, loss = distiller.evaluate(x_test, y_test, verbose = 1) print('test loss = ', loss) print('test accuracy = ',acc)

With t = 6, we have got 75% accuracy which is better than what we got with t = 2.

This way, we can do more iterations by changing the values of hypermeters alpha (α) and temperature (t) in order to get better accuracy.

Model 3: Student Model without Knowledge Distillation

Now we will check the student model without Knowledge Distillation. Here there will be no coordination with the teacher network and there will be only one loss function i.e. Student Loss.

The student model remains the same as the previous ithout distillation.

Compiling and running the model:

opti = Adam(learning_rate=1e-4, beta_1=0.9, beta_2=0.999, ep , decay=0.001) earlystop = EarlyStopping(monitor='val_acc', patience=5, verbose=1) filepath="model_save/weights-{epoch:02d}-{val_accuracy:.4f}.hdf5" checkpoint = ModelCheckpoint(filepath=filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max') callbacks = [earlystop ] s_model_2_hist =, validation_data = validation_generator, validation_steps=10, steps_per_epoch = 90, epochs = 50, callbacks=callbacks)

Our model stopped in 13 epochs as we had used early stop callback if there is no improvement in validation accuracy in 5 epochs.

Plotting the loss and accuracy for each epoch:

import matplotlib.pyplot as plt plt.figure(1) # summarize history for accuracy plt.subplot(211) plt.plot(s_model_2_hist.history['acc']) plt.plot(s_model_2_hist.history['val_acc']) plt.title('model accuracy') plt.ylabel('accuracy') plt.xlabel('epoch') plt.legend(['train', 'valid'], loc='lower right') # summarize history for loss plt.subplot(212) plt.plot(s_model_2_hist.history['loss']) plt.plot(s_model_2_hist.history['val_loss']) plt.title('model loss') plt.ylabel('loss') plt.xlabel('epoch') plt.legend(['train', 'valid'], loc='upper right') plt.tight_layout()

Checking the Test Accuracy:


loss, acc = s_model_2.evaluate(x_test, y_test, verbose = 1)

print(‘test loss = ‘, loss)

print(‘test accuracy = ‘,acc)

Here we are able to achieve 64% accuracy on the test data.

Result Summary:

Below is the comparison of all four models that are made in this case study:

S. No. Model No. of Parameters Hyperparameter Test Accuracy

1 Teacher Model 27 M – 77%

2 Student Model with Distillation 296 k α = 0.5, t = 2 74%

3 Student Model with Distillation 296 k α = 0.5, t = 6 75%


Student Model without Distillation

296 k – 64%

As seen from the above table, with Knowledge distillation, we have achieved 75% accuracy with a very lite neural network. We can play around with the hypermeters α and t to improve it further.


In this article, we saw that Knowledge Distillation can compress a Deep CNN while maintaining the accuracy so that it can be deployed on embedded systems that have less storage and computational power.

We used Knowledge Distillation on the Pneumonia detection problem from x-ray images. By distilling Knowledge from a Teacher Network having 27M parameters to a Student Network having only 0.296M parameters (almost 100 times lighter), we were able to achieve almost the same accuracy. With more hyperparameter iterations and ensembling of multiple students networks as mentioned in reference [3], the performance of the student model can be further improved.


1) Identifying Medical Diagnoses and Treatable Diseases by Image-Based Deep Learning 2023.

2) Dataset: Kermany, Daniel; Zhang, Kang; Goldbaum, Michael (2024), “Labeled Optical Coherence Tomography (OCT) and Chest X-Ray Images for Classification”, Mendeley Data, V2, doi: 10.17632/rscbjbr9sj.2

3) Designing Lightweight Deep Learning Models for Echocardiography View Classification 2023.

The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion. 


Case Study: Outsourcing Link Building To Grow Traffic By 63,000+ Visitors

This is a sponsored post written by Page One Power. The opinions expressed in this article are the sponsor’s own.

One unique service we’re happy to offer at Page One Power is our white label individual link building service. We primarily offer this service to SEO agencies and digital marketing agencies.

This service helps agencies purchase individual links built by the Page One Power team, which they can then resell to their clients as part of a broader digital marketing or SEO campaign.

We’ve been able to help many agencies achieve great results for their clients with our individual link building service — let’s take a look at some of those results.

Increasing Traffic by 34% Over 18 Months with Link Building

Since 2012, we’ve built over 60,000 links for our clients, and 178 of them have been for this individual link client, who we’ve worked with for just over 18 months. These links were built through our partnership with the SEO agency of record who represents the client.

The 178 links we’ve built for this client include:

55 resource page links.

123 in-content links.

A strong content marketing strategy is a great indicator that a client may be the right fit for our individual link building services.

The best candidates for our individual link building services already have great on-site optimization and existing linkable content on their sites — they just need help with the intensive process of manually building links.

In this case, the agency of record that represents this client does a lot of great SEO work for them, ensuring their site is technically optimized, has strong internal links, and plenty of existing high-quality content.

The agency also assisted this client with paid search, improving performance through better keyword and local targeting, and reducing waste.

The client had many resource pages on their website, in addition to plenty of other linkable content, making them a great candidate for individual link building. After reviewing this client’s website, we knew they were ready for links!

The existing content available made it easy to identify our link building opportunities.

We began by leveraging opportunities to build links back to the linkable assets on the client’s site with in-content link building.

With our in-content link building service, we first identify the linkable pages on the client’s site. Our content writing team then crafts high-quality articles for relevant third-party sites, which include links to the client’s site.

Our writers identified plenty of useful pieces of content on the client’s website, then connected them to relevant in-content opportunities to link where they added value to readers.

We then began to pursue resource page link building opportunities.

The client had several resources on their website that naturally earned links. These resource pages had clear value: they were helpful and educational, which made it easy for our team to communicate their value to other site owners and build relevant links!

The Results

While we don’t require contracts for our white label individual link building service, we’ve been helping the agency of record with this client for just over 18 months.

During this time, we’ve been excited to see organic traffic to the client’s site increase by 34 percent!

The links we’ve built, in combination with the agency of record’s content and technical SEO services, have contributed to an increase from 190,000 to 253,900 organic visitors per month.

The client has also seen increases in keyword rankings in the top 3 results. We’ve helped them grow their presence from 3,763 to 5,888 top 3 keyword ranking results. That’s a 56 percent increase in keyword visibility in the top 3 results.

The resource pages on this client’s website had a local component: those pages helped visitors connect with local resources. The links we built contributed to an increase in geo-specific traffic — an important KPI for this client.

After discussions with the agency about their plan for this client, we knew they were a great fit for our individual link building services.

The work they’ve done to optimize the client’s site and improve their paid search performance provided the support our team needed to achieve success with our off-page optimization services.

Through our partnership, we’ve been able to implement an optimized marketing plan that achieves great results for this client.

This link building service allows agencies to outsource the intensive process of manual link building. We help our agency partners meet their clients’ SEO goals, so they can focus on the other digital marketing and SEO tactics they specialize in.

While this service might seem similar to some services offered by other popular link building providers, the difference lies in what makes all of our work unique.

To ensure all of the links we build drive results, this service is only offered to a very specific set of clients who are subject to a stringent set of content and optimization requirements.

Link building should always be part of a larger SEO strategy, so before we begin this service, we take time to discuss the agency’s plans for the client and the client’s current SEO. This helps us identify whether the client is a good fit for the service, and informs our link building strategy.

At Page One Power, we offer a full range of custom SEO solutions that help our clients achieve better rankings, improved traffic, and results from their organic search presence.

If you’d like to learn how our team can help you achieve better results, check out more of our case studies or contact one of our SEO specialists today.

Image Credits

How Does Mysql Union Work

Introduction to MySQL Union

MySQL Union combines the output of two or more “SELECT” statements. The output of the “UNION” will be without duplicate rows. The number of fields in the table should be the same, and the data type of the columns should be the same. If you don’t want the duplicate rows to be ignored, we can do it with the “UNION ALL”. In the result set of the UNION table, the column name will be the same as the column name of the first select statement. In this session, let us learn more about the usage of the UNION and let see the examples of it: –

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others


Now let us see the syntax:

SELECT column_1, column_2,...column_n FROM First_tables [WHERE conditions] UNION [DISTINCT] SELECT column_1, column_2,...column_n FROM Second_tables [WHERE conditions]; How Does MySQL Union Work? Table1 create table uniona ( cola INT ); Table2 create table unionb ( colb INT );

Insert data into the tables as below: – Below is for the “uniona” table.

insert into uniona values (99); insert into uniona values (95); insert into uniona values (94); insert into uniona values (93); insert into uniona values (92); insert into uniona values (91); insert into uniona values (99);

Select the items for the table “uniona”: –

select * from uniona;

Let us see the screenshot for the same: –

Insert data into the tables as below: – Below is for the “unionb” table.

insert into unionb values (99); insert into unionb values (34); insert into unionb values (35); insert into unionb values (33); insert into unionb values (32); insert into unionb values (31); insert into unionb values (30); insert into unionb values (29); insert into unionb values (28);

Select the items for the table “unionb”: –

select * from unionb;

Let us see the screenshot for the same: –

Now let us perform union operation on the above tables: –

select * from uniona union select * from unionb;

Select the items for the table “uniona” and “unionb” and perform the union: –

Let us see the screenshot for the same: –


Now let us perform UNION on three tables as below: –

--Table1: - create table TEST_A ( cola INT ); --Table2: - create table TEST_B ( colb INT ); --Table3: - create table TEST_C ( colc INT ); insert into test_a values (1); insert into test_a values (2); insert into test_a values (3); insert into test_a values (4);

Let us see the columns of the table: –

select * from test_a; insert into test_b values (1); insert into test_b values (5); insert into test_b values (6); insert into test_b values (7); insert into test_b values (8);

Let us see the columns of the table: –

insert into test_c values (1); insert into test_c values (10); insert into test_c values (11); insert into test_c values (12); insert into test_c values (13);

Let us see the columns of the table: –


Screenshot for the above: –

select * from test_a union select * from test_b union select * from test_c


Here in the above output, we need to check two things: –

The column name of the result set is the column name of the first “select” statement. Here it is “cola”.

The second thing is that we can see that there is a duplicate row in all the tables of value “1”. But in the result set, UNION ignores the duplicate because we have only one row of data, “1”.

Screenshot for the same: –

Example of MySQL Union

Actual Table:-

create table St_marks ( subject_name varchar(20), marks int ); insert into st_marks values ('English', 98); insert into st_marks values ('Mathematics', 93); insert into st_marks values ('Physics', 78); insert into st_marks values ('Chemistry', 67); insert into st_marks values ('Art', 43); insert into st_marks values ('Music Class', 67); select * from st_marks;

Backup table:-

create table St_marks_bkup ( subject_name varchar(20), marks int ); insert into st_marks_bkup values ('English', 98); insert into st_marks_bkup values ('Mathematics', 93); insert into st_marks_bkup values ('Physics', 78); insert into st_marks_bkup values ('Chemistry', 67); insert into st_marks_bkup values ('Art', 43); insert into st_marks_bkup values ('Music Class', 67); select * from st_marks_bkup;


A screenshot for the above is given below: –



The screenshot is for the same: –


Things that need to remember are as below: –

MySQL Union combines the output of two or more “SELECT” statements. The output of the “UNION” will be without duplicate rows.

The number of fields in the table should be the same, and the data type of the columns should be the same. If you don’t want the duplicate rows to be ignored, we can do it with the “UNION ALL”.

In the result set of the UNION table, the column name will be the same as the column name of the first select statement.

Recommended Articles

We hope that this EDUCBA information on “MySQL Union” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Case Study: Union Pacific Keeps Data On Track on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!