SlideShare a Scribd company logo
1 of 32
How To Use SQL In Excel
The MySQL For Excel Add-inn
Author: Victor Cocis
Contact: victorc@web.de
Introduction
 Processing large amount of data, like in-place update, or wildcard-based
filtering, is hard to manage using Excel’s tools, but with a little help of SQL
can be done easy
 With the MySQL for Excel Add-in you can do this in 3 simple steps:
 Export data from Excel to a local MySQL Server
 Use a MySQL client to process the data
 Import results back to Excel
Needed Tools
 Visual Studio 2010 Tools for Office
Runtime. Download it from Microsoft
 The MySQL for Excel Add-in (free).
Download it from Oracle
 A standalone MySQL Server. This
example uses mini-server, portable,
download it from Sourceforge
 A MySQL client. Recommendation
HeidiSQL, portable, download it from
HeidiSQL
Installation
 The Visual Studio Runtime
and the MySQL for Excel
Add-in are coming as
Windows Installers
 After running the
installation, the add-in will
appear in the „Data“ Tab of
Excel.
 Mini-Server and HeidiSQL
have portable versions, just
unzip them in a folder of
choice
Connecting All Together
Connecting All
Together
 Start the Mini-server by clicking
the mysql_start.bat file from the
installation folder. A command
prompt will inform you if the
server is running
 Connect HeidiSQL and create a
database (These steps are
necessary only once)
 Start HeidiSQL from its
installation folder
(heidisql.exe)
 In the right bottom corner
click New -> Session in root
folder
Connecting All Together
 The session manager will create
a session called „Unnamed“,
rename it to e.g. „mysession“
 Set following connection
parameters
 Hostname: „localhost“ or
„127.0.0.1“
 User: root
 Password: root
 Port: 3311
 Database: blank
Connecting All
Together
 In the screen that opens
right-click the session
name („mysession“ in this
example) the Create new -
> Database and enter a
database name, e. g.
„mydatabase“ in the form
that opens. You will then
see the new database on
the right panel.
*Note: information_schema and
mysql are system databases
Connecting All Together
 Connect Excel tot he database
(These steps are necessary only
once)
 Open a blank excel workbook
and choose Data from the menu.
You will see the MySQL for Excel
panel on the left, as described
in Installation
 Click on New Connection and
enter the same parameters as
described in slide #7 then click
OK
Connecting All Together
 In the panel double-click the connection to open it, then the database to connect
to
Practical
Examples
 For the examples we will use
 A Price and Stock List
Name Category Price Stock
Ballantines Finest Scotch 58.90 120
Bowmore 12 Years Single Malt 48.90 111
Canadian Club Canadian 50.90 114
Canadian Club 12 Years Canadian 43.90 108
Chivas Regal 12 Years Scotch 32.90 no stock
Chivas Regal 18 Years Scotch 32.90 120
Crown Royal Canadian 37.90 102
Crown Royal Reserve Canadian 33.90 108
Dalmore Scotch Single Malt 35.90 101
Dewars 12 Years Scotch 35.90 118
Dewars White Label Scotch 35.90 118
Glenfiddich 12 Years Single Malt 38.90 114
Glenfiddich 15 Years Single Malt 35.90 108
Glenfiddich 18 Years Single Malt 37.90 no stock
Glenlivet 12 Years Single Malt 39.90 no stock
Glenlivet 15 Years Single Malt 48.90 115
Glenlivet 18 Years Single Malt 45.90 115
J and B Scotch 57.90 114
Jack Daniels Bourbon 36.90 104
Jameson Irish 40.90 103
Jim Beam Bourbon 40.90 116
Johnny Walker Black Label Scotch 33.90 110
Johnny Walker Blue Label Scotch 56.90 100
Johnny Walker Red Label Scotch 52.90 115
Old Grand Dad Bourbon 59.90 104
Sir Edwards Scotch 34.90 no stock
Teachers Scotch 58.90 110
Tullamore Dew Irish 33.90 115
VAT 69 Scotch 37.90 104
Practical
Examples
 An Incoming Deliver List
*Note: You can download the lists as
Excel files from
https://www.mediafire.com/file/h8qu8
0uztmgc70f/Whyskey_Sample.xlsx/file
Name Delivered
Ballantines Finest 40
Bowmore 12 Years 50
Canadian Club 40
Chivas Regal 12 Years 60
J and B 55
Jack Daniels 40
Jameson 50
Jim Beam 50
Johnny Walker Black Label 60
Old Grand Dad 30
Sir Edwards 40
Teachers 60
Tullamore Dew 60
VAT 69 50
Practical Examples – Export Data And
Create Table
 Mark the columns you wish to
export and in the MySQL For Excel
panel click „Export Excel Data To
New Table “
Practical Examples – Export Data And
Create Table
Practical Examples – Export Data And
Create Table
 Click ok in next screen and in
the panel you will see the wizard
has created the table.
Practical Examples – Export Data And
Create Table
 Examine the table in HeidiSQL
(click refresh in the upper left
corner of Heidi if the table is not
yet visible)
 The wizard has added a
numerical id. First Excel table row
has been used as header, to name
the fields. Column containing strings
have been formatted as varchar
with the maximum length of
contained string. The „Stock“
column is also varchar, as it contains
„no stock“ on some positions.
Practical Examples - Update and
Regularize Column
 To make the „Stock“ column
numeric, let’s first replace „no
stock“ with 0 (zero). Click the
„Query“ tab in Heidi and run
following query:
UPDATE whiskey SET Stock=0
WHERE Stock="no stock";
Practical Examples - Update and
Regularize Column
 Click the „Data“ tab
to check modified data
Practical Examples - Update and
Regularize Column
 Back tot he „Table“
tab, double click the
„Datatype“ oft he Stock
field and choose „INT“
from the dropdown and
then „Save“
Practical Examples -
Update and
Regularize Column
 Back to Excel, click „Import
MySQL Data“ to update the
changes. You can do this over
existing data, or in a new
Worksheet, or even a new file
 The add-in has also created a
connection between the Excel
table and the database. Just
clicking „Refresh“ in the „Data“
tab of Excel and changes in the
database will be reflected in
Excel
Practical Examples -
Mirror Back Data
Changes in Excel
Unfortunately changes in Excel
won’t be updated in the database.
„Edit MySQL Data“ provides a way
to change MySQL data, but is a bit
tricky to use. An easy way to do
this:
 In Heidi SQL, right click the
table, then choose “Empty
table(s)”. This will delete data, but
preserve the table structure
 Back in Excel, select the
columns, then select the table in
the right pane and click “Append
Excel Data to Table”
Practical Examples - Mirror Back Data
Changes in Excel
 On the next screen
check the box “First
Row Contains Column
Names” and verify that
columns are correctly
mapped. Then click
“Append”
Practical Examples - Mirror Back Data
Changes in Excel
 Refresh the table in
Heidi to verify data is
correct
Practical Examples
– Save Filters
 In this example, the whiskey
shop orders weekly drinks where
the stock is below 110 bottles.
 In Heidi right click your
database (“mydatabase”) then
choose “If you use certain filters
regularly, you can store them as
views in the database and use
them by just a click Create new”
-> “View”
Practical Examples
– Save Filters
 Give it a name, e.g. “Order”
and write your SELECT
statement:
SELECT * FROM whiskey WHERE
Stock<110;
then save it.
Practical Examples – Save Filters
 Back to Excel right click in the panel with data objects and choose
“Refresh Database Objects” to display the view
Practical Examples
– Save Filters
 Now choose where you want to
display the data, it might be same
sheet, a different one or even a
new file.
 Click the “order” view, then
click “Import MySQL Data”
 Next time you need the filter,
just update your data as described
in Mirror Back Data Changes in
Excel and click “Refresh” in the
data tab*
*Note: We observed cases when the
view didn’t refresh after a table
update. We recommend to manually
refresh the view from the MySQL client
Practical Examples
– Save Filters
 The most help is, of course,
in case of complex filters, with
multiple conditions, which you
don’t have to build each time
with Excel filter wizard.
 You can also use operations or
features not present in Excel.
 For example, the supplier of
the whiskey shop has an offer for
whiskey labeled older than 12
years. Hard to filter such names
in Excel, but very simple using
regular expression in SQL:
SELECT * FROM whiskey WHERE
Name REGEXP "1[3-9] Years";
Practical Examples – In-Place Editing
 This requires in Excel at least writing a formula and dragging it for all values,
then override the original values. Much simpler with MySQL for Excel.
 A simple one: increase all prices by 10%:
 Run following query in Heidi:
UPDATE whiskey SET Price=Price*1.1;
 then in Excel click “Refresh” in the “Data” Tab or import data to another
sheet or file.
Practical Examples
– In-Place Editing
 A more complex one: a new delivery is
here, update the stocks. In Excel this needs
some lookups and IF’s and overriding the
original values.
 With SQL first export the delivery data as
described in Export Data and Create Table, to
fill data in a “delivery” table
 As names are identical, we will use that
field to match the 2 tables. Run following
query in Heidi:
UPDATE whiskey LEFT JOIN delivery ON
whiskey.Name=delivery.Name SET
Stock=Stock+Delivery;
 then in Excel click the “whiskey” sheet
and click “Refresh” in the “Data” Tab or import
data to another sheet or file
Practical Examples – Delete Rows Based on
Filter Criteria
 This is another task not straight forward in Excel but quick to do with SQL.
 To delete all products wit zero stock after delivery (because supplier won’t
deliver them anymore), run following query in Heidi:
DELETE FROM whiskey WHERE Stock=0;
 then in Excel click “Refresh” in the “Data” Tab or import data to another
sheet or file.
Notes
 You can use a MySQL client of choice, functionalities described here are
common to most database clients
 You can use the actual version of the MySQL Server as a local host installation
 Some processes described will show informative or warning pop-ups, these
were ignored in the text, just click “Ok” or “Continue” when they show up
 All SQL SELECT statements select all the fields just for readability, use a list
of fields of your need with SQL

More Related Content

Similar to Using SQL in Excel

Style Intelligence Evaluation Documentation
Style Intelligence Evaluation DocumentationStyle Intelligence Evaluation Documentation
Style Intelligence Evaluation DocumentationArleneWatson
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsDharmaraj Borse
 
Itm310 problem solving #7 complete solutions correct answers key
Itm310 problem solving #7 complete solutions correct answers keyItm310 problem solving #7 complete solutions correct answers key
Itm310 problem solving #7 complete solutions correct answers keySong Love
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolRavi Kumar Lanke
 
Business Analysis and Reporting
Business Analysis and Reporting Business Analysis and Reporting
Business Analysis and Reporting waseem zeeshan
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandiserswebhostingguy
 
It203 class slides-unit5
It203 class slides-unit5It203 class slides-unit5
It203 class slides-unit5Matthew Moldvan
 
Xcelsius Best Practices 2008
Xcelsius Best Practices 2008Xcelsius Best Practices 2008
Xcelsius Best Practices 2008BI Brainz Group
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxLab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxVinaOconner450
 
Power ups Parameters PowerBI
Power ups Parameters PowerBIPower ups Parameters PowerBI
Power ups Parameters PowerBIJohann Krugell
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxLab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxDIPESH30
 
SQL Server Database Fundamentals Maintain SQL DB.pdf
SQL Server Database Fundamentals Maintain SQL DB.pdfSQL Server Database Fundamentals Maintain SQL DB.pdf
SQL Server Database Fundamentals Maintain SQL DB.pdfssuserd04633
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-noteLeerpiny Makouach
 

Similar to Using SQL in Excel (20)

Style Intelligence Evaluation Documentation
Style Intelligence Evaluation DocumentationStyle Intelligence Evaluation Documentation
Style Intelligence Evaluation Documentation
 
ssis lab
ssis labssis lab
ssis lab
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation Steps
 
Itm310 problem solving #7 complete solutions correct answers key
Itm310 problem solving #7 complete solutions correct answers keyItm310 problem solving #7 complete solutions correct answers key
Itm310 problem solving #7 complete solutions correct answers key
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Use sqlite
Use sqliteUse sqlite
Use sqlite
 
Creating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration toolCreating a repository using the oracle business intelligence administration tool
Creating a repository using the oracle business intelligence administration tool
 
dbadapters
dbadaptersdbadapters
dbadapters
 
Mule data bases
Mule data basesMule data bases
Mule data bases
 
Using Mysql.pptx
Using Mysql.pptxUsing Mysql.pptx
Using Mysql.pptx
 
Business Analysis and Reporting
Business Analysis and Reporting Business Analysis and Reporting
Business Analysis and Reporting
 
Excel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for MerchandisersExcel and SQL Quick Tricks for Merchandisers
Excel and SQL Quick Tricks for Merchandisers
 
It203 class slides-unit5
It203 class slides-unit5It203 class slides-unit5
It203 class slides-unit5
 
Xcelsius Best Practices 2008
Xcelsius Best Practices 2008Xcelsius Best Practices 2008
Xcelsius Best Practices 2008
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docxLab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.).docx
 
Power ups Parameters PowerBI
Power ups Parameters PowerBIPower ups Parameters PowerBI
Power ups Parameters PowerBI
 
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docxLab 2 Work with Dictionary and Create Relational Database (60 pts.docx
Lab 2 Work with Dictionary and Create Relational Database (60 pts.docx
 
SQL Server Database Fundamentals Maintain SQL DB.pdf
SQL Server Database Fundamentals Maintain SQL DB.pdfSQL Server Database Fundamentals Maintain SQL DB.pdf
SQL Server Database Fundamentals Maintain SQL DB.pdf
 
database-querry-student-note
database-querry-student-notedatabase-querry-student-note
database-querry-student-note
 

Recently uploaded

20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Recently uploaded (20)

20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

Using SQL in Excel

  • 1. How To Use SQL In Excel The MySQL For Excel Add-inn Author: Victor Cocis Contact: victorc@web.de
  • 2. Introduction  Processing large amount of data, like in-place update, or wildcard-based filtering, is hard to manage using Excel’s tools, but with a little help of SQL can be done easy  With the MySQL for Excel Add-in you can do this in 3 simple steps:  Export data from Excel to a local MySQL Server  Use a MySQL client to process the data  Import results back to Excel
  • 3. Needed Tools  Visual Studio 2010 Tools for Office Runtime. Download it from Microsoft  The MySQL for Excel Add-in (free). Download it from Oracle  A standalone MySQL Server. This example uses mini-server, portable, download it from Sourceforge  A MySQL client. Recommendation HeidiSQL, portable, download it from HeidiSQL
  • 4. Installation  The Visual Studio Runtime and the MySQL for Excel Add-in are coming as Windows Installers  After running the installation, the add-in will appear in the „Data“ Tab of Excel.  Mini-Server and HeidiSQL have portable versions, just unzip them in a folder of choice
  • 6. Connecting All Together  Start the Mini-server by clicking the mysql_start.bat file from the installation folder. A command prompt will inform you if the server is running  Connect HeidiSQL and create a database (These steps are necessary only once)  Start HeidiSQL from its installation folder (heidisql.exe)  In the right bottom corner click New -> Session in root folder
  • 7. Connecting All Together  The session manager will create a session called „Unnamed“, rename it to e.g. „mysession“  Set following connection parameters  Hostname: „localhost“ or „127.0.0.1“  User: root  Password: root  Port: 3311  Database: blank
  • 8. Connecting All Together  In the screen that opens right-click the session name („mysession“ in this example) the Create new - > Database and enter a database name, e. g. „mydatabase“ in the form that opens. You will then see the new database on the right panel. *Note: information_schema and mysql are system databases
  • 9. Connecting All Together  Connect Excel tot he database (These steps are necessary only once)  Open a blank excel workbook and choose Data from the menu. You will see the MySQL for Excel panel on the left, as described in Installation  Click on New Connection and enter the same parameters as described in slide #7 then click OK
  • 10. Connecting All Together  In the panel double-click the connection to open it, then the database to connect to
  • 11. Practical Examples  For the examples we will use  A Price and Stock List Name Category Price Stock Ballantines Finest Scotch 58.90 120 Bowmore 12 Years Single Malt 48.90 111 Canadian Club Canadian 50.90 114 Canadian Club 12 Years Canadian 43.90 108 Chivas Regal 12 Years Scotch 32.90 no stock Chivas Regal 18 Years Scotch 32.90 120 Crown Royal Canadian 37.90 102 Crown Royal Reserve Canadian 33.90 108 Dalmore Scotch Single Malt 35.90 101 Dewars 12 Years Scotch 35.90 118 Dewars White Label Scotch 35.90 118 Glenfiddich 12 Years Single Malt 38.90 114 Glenfiddich 15 Years Single Malt 35.90 108 Glenfiddich 18 Years Single Malt 37.90 no stock Glenlivet 12 Years Single Malt 39.90 no stock Glenlivet 15 Years Single Malt 48.90 115 Glenlivet 18 Years Single Malt 45.90 115 J and B Scotch 57.90 114 Jack Daniels Bourbon 36.90 104 Jameson Irish 40.90 103 Jim Beam Bourbon 40.90 116 Johnny Walker Black Label Scotch 33.90 110 Johnny Walker Blue Label Scotch 56.90 100 Johnny Walker Red Label Scotch 52.90 115 Old Grand Dad Bourbon 59.90 104 Sir Edwards Scotch 34.90 no stock Teachers Scotch 58.90 110 Tullamore Dew Irish 33.90 115 VAT 69 Scotch 37.90 104
  • 12. Practical Examples  An Incoming Deliver List *Note: You can download the lists as Excel files from https://www.mediafire.com/file/h8qu8 0uztmgc70f/Whyskey_Sample.xlsx/file Name Delivered Ballantines Finest 40 Bowmore 12 Years 50 Canadian Club 40 Chivas Regal 12 Years 60 J and B 55 Jack Daniels 40 Jameson 50 Jim Beam 50 Johnny Walker Black Label 60 Old Grand Dad 30 Sir Edwards 40 Teachers 60 Tullamore Dew 60 VAT 69 50
  • 13. Practical Examples – Export Data And Create Table  Mark the columns you wish to export and in the MySQL For Excel panel click „Export Excel Data To New Table “
  • 14. Practical Examples – Export Data And Create Table
  • 15. Practical Examples – Export Data And Create Table  Click ok in next screen and in the panel you will see the wizard has created the table.
  • 16. Practical Examples – Export Data And Create Table  Examine the table in HeidiSQL (click refresh in the upper left corner of Heidi if the table is not yet visible)  The wizard has added a numerical id. First Excel table row has been used as header, to name the fields. Column containing strings have been formatted as varchar with the maximum length of contained string. The „Stock“ column is also varchar, as it contains „no stock“ on some positions.
  • 17. Practical Examples - Update and Regularize Column  To make the „Stock“ column numeric, let’s first replace „no stock“ with 0 (zero). Click the „Query“ tab in Heidi and run following query: UPDATE whiskey SET Stock=0 WHERE Stock="no stock";
  • 18. Practical Examples - Update and Regularize Column  Click the „Data“ tab to check modified data
  • 19. Practical Examples - Update and Regularize Column  Back tot he „Table“ tab, double click the „Datatype“ oft he Stock field and choose „INT“ from the dropdown and then „Save“
  • 20. Practical Examples - Update and Regularize Column  Back to Excel, click „Import MySQL Data“ to update the changes. You can do this over existing data, or in a new Worksheet, or even a new file  The add-in has also created a connection between the Excel table and the database. Just clicking „Refresh“ in the „Data“ tab of Excel and changes in the database will be reflected in Excel
  • 21. Practical Examples - Mirror Back Data Changes in Excel Unfortunately changes in Excel won’t be updated in the database. „Edit MySQL Data“ provides a way to change MySQL data, but is a bit tricky to use. An easy way to do this:  In Heidi SQL, right click the table, then choose “Empty table(s)”. This will delete data, but preserve the table structure  Back in Excel, select the columns, then select the table in the right pane and click “Append Excel Data to Table”
  • 22. Practical Examples - Mirror Back Data Changes in Excel  On the next screen check the box “First Row Contains Column Names” and verify that columns are correctly mapped. Then click “Append”
  • 23. Practical Examples - Mirror Back Data Changes in Excel  Refresh the table in Heidi to verify data is correct
  • 24. Practical Examples – Save Filters  In this example, the whiskey shop orders weekly drinks where the stock is below 110 bottles.  In Heidi right click your database (“mydatabase”) then choose “If you use certain filters regularly, you can store them as views in the database and use them by just a click Create new” -> “View”
  • 25. Practical Examples – Save Filters  Give it a name, e.g. “Order” and write your SELECT statement: SELECT * FROM whiskey WHERE Stock<110; then save it.
  • 26. Practical Examples – Save Filters  Back to Excel right click in the panel with data objects and choose “Refresh Database Objects” to display the view
  • 27. Practical Examples – Save Filters  Now choose where you want to display the data, it might be same sheet, a different one or even a new file.  Click the “order” view, then click “Import MySQL Data”  Next time you need the filter, just update your data as described in Mirror Back Data Changes in Excel and click “Refresh” in the data tab* *Note: We observed cases when the view didn’t refresh after a table update. We recommend to manually refresh the view from the MySQL client
  • 28. Practical Examples – Save Filters  The most help is, of course, in case of complex filters, with multiple conditions, which you don’t have to build each time with Excel filter wizard.  You can also use operations or features not present in Excel.  For example, the supplier of the whiskey shop has an offer for whiskey labeled older than 12 years. Hard to filter such names in Excel, but very simple using regular expression in SQL: SELECT * FROM whiskey WHERE Name REGEXP "1[3-9] Years";
  • 29. Practical Examples – In-Place Editing  This requires in Excel at least writing a formula and dragging it for all values, then override the original values. Much simpler with MySQL for Excel.  A simple one: increase all prices by 10%:  Run following query in Heidi: UPDATE whiskey SET Price=Price*1.1;  then in Excel click “Refresh” in the “Data” Tab or import data to another sheet or file.
  • 30. Practical Examples – In-Place Editing  A more complex one: a new delivery is here, update the stocks. In Excel this needs some lookups and IF’s and overriding the original values.  With SQL first export the delivery data as described in Export Data and Create Table, to fill data in a “delivery” table  As names are identical, we will use that field to match the 2 tables. Run following query in Heidi: UPDATE whiskey LEFT JOIN delivery ON whiskey.Name=delivery.Name SET Stock=Stock+Delivery;  then in Excel click the “whiskey” sheet and click “Refresh” in the “Data” Tab or import data to another sheet or file
  • 31. Practical Examples – Delete Rows Based on Filter Criteria  This is another task not straight forward in Excel but quick to do with SQL.  To delete all products wit zero stock after delivery (because supplier won’t deliver them anymore), run following query in Heidi: DELETE FROM whiskey WHERE Stock=0;  then in Excel click “Refresh” in the “Data” Tab or import data to another sheet or file.
  • 32. Notes  You can use a MySQL client of choice, functionalities described here are common to most database clients  You can use the actual version of the MySQL Server as a local host installation  Some processes described will show informative or warning pop-ups, these were ignored in the text, just click “Ok” or “Continue” when they show up  All SQL SELECT statements select all the fields just for readability, use a list of fields of your need with SQL