SlideShare a Scribd company logo
Coding Potpourri:
                            MySQL
                                  Nicole C. Engard
               Director of Open Source Education, ByWater Solutions
                 Author of Practical Open Source Software for Libraries

Monday, July 25, 2011
My What?

                    • MySQL: My Structured Query Language
                    • Relational Database Management System
                    • Licensed with the GNU GPL
                     • That means it’s Open Source
                    • Used to organize data in a structured way
Monday, July 25, 2011
Who’s Using It?
                    • MySQL is the database behind many
                        popular web based applications
                        • Wordpress         • YouTube
                        • Drupal            • Flickr
                        • Wikipedia         • Ebay
                        • Facebook          • Google (not searches)
Monday, July 25, 2011
Reading Table Structure
                  CREATE TABLE `branches` (
                    `branchcode` varchar(10) NOT NULL default '',
                    `branchname` mediumtext NOT NULL,
                    `branchaddress1` mediumtext,
                    `branchaddress2` mediumtext,
                    `branchaddress3` mediumtext,
                    `branchphone` mediumtext,
                    `branchfax` mediumtext,
                    `branchemail` mediumtext,
                    UNIQUE KEY `branchcode` (`branchcode`)
                  )
Monday, July 25, 2011
Reading Table Structure
              •         This table’s name is ‘branches’ and it stores the
                        information about libraries or branches in Koha.
              •         Each field is easy to identify because of its name
                        (ex. branchname is the library name).
              •         A field with a number in parens after it is a field
                        that is limited in size.
                    •     For example varchar(10) means the field can
                          have no more than 10 characters in it
              •         Lastly, we see that ‘branchcode’ is the unique key
                        or unique identifier in the table.
Monday, July 25, 2011
Inserting Data
                • Using the branches table enter a branch’s
                        info

                        INSERT INTO branches (branchcode,
                        branchname, branchaddress1,
                        branchaddress2, branchphone, branchemail)
                        VALUES (‘LIB’, ‘My Library’, ‘123 Library
                        Road’, ‘Philadelphia, PA’, ‘215.555.1234’,
                        ‘info@library.com’);
Monday, July 25, 2011
Querying MySQL
                 • To query a single table you will structure your
                        query like this:
                 • SELECT column_names FROM table_name
                        [WHERE ...conditions] [ORDER
                        BY ...conditions];
                 • Statements in brackets are optional
                 • You can also select everything in a table by
                        using an * in place of column_names

Monday, July 25, 2011
Querying MySQL
               • Using the branches table let’s query the data
               • This query will pull out only the Branch Names
                        and Emails and put them in ascending order by
                        name

                        SELECT branchname, branchemail FROM
                        branches ORDER BY branchname ASC;



Monday, July 25, 2011
Querying MySQL
               • Using branches let’s get the address info from
                        one specific branch

                        SELECT branchname, branchaddress1,
                        branchaddress2, branchaddress3, branchemail
                        FROM branches WHERE branchcode=‘LIB’;




Monday, July 25, 2011
Querying MySQL
             • Using branches let’s pull out the branch’s phone
                        and fax in one column

                        SELECT CONCAT(‘ph. ’, branchphone, ‘ fax ’,
                        branchfax) as ‘contact info’ FROM branches
                        WHERE branchcode= ‘LIB’;




Monday, July 25, 2011
Another Table
           CREATE TABLE `issues` (
             `borrowernumber` int(11) default NULL,
             `itemnumber` int(11) default NULL,
             `date_due` date default NULL,
             `branchcode` varchar(10) default NULL,
             `returndate` date default NULL,
             `return` varchar(4) default NULL,
             `renewals` tinyint(4) default NULL,
             `issuedate` date default NULL,
             KEY `issuesborridx` (`borrowernumber`),
             KEY `issuesitemidx` (`itemnumber`),
           )
Monday, July 25, 2011
Joining Tables
              •         Using branches and issues let’s find out how many
                        items circulated at each branch in a specific time
                        period

                        SELECT b.branchname, count(i.branchcode) as
                        count FROM issues i LEFT JOIN branches b ON
                        (i.branchcode=b.branchcode) WHERE i.issuedate
                        BETWEEN ‘2011-06-01’ AND ‘2011-07-01’ GROUP
                        BY b.branchcode ORDER BY count DESC;




Monday, July 25, 2011
Date & Time Functions
                    • The most common use for reports is for
                        end of the month or end of the year
                        statistics
                    • The MySQL manual on Date & Time
                        functions is essential for these queries
                        • http://dev.mysql.com/doc/refman/5.6/en/
                          date-and-time-functions.html

Monday, July 25, 2011
String Functions
                    • Often you want to join two or more
                        strings together, find a part of a string or
                        even change a part of a string
                    • String functions are defined in the MySQL
                        manual
                        • http://dev.mysql.com/doc/refman/5.6/en/
                          string-functions.html

Monday, July 25, 2011
Math Functions
                    • Using MySQL you can get fancy with
                        statistics by using the number related
                        functions
                    • The Numeric Functions section of the
                        manual can help you here
                        • http://dev.mysql.com/doc/refman/5.6/en/
                          numeric-functions.html

Monday, July 25, 2011
Common Functions
                    •   COUNT(FIELD) or SUM(FIELD)
                        •Counts the number of or adds up the total
                         value of results in a column
                    •   CURDATE()
                        •Is the current date (not time, just date)
                    •   MONTH(FIELD) and YEAR(FIELD)
                        •Return the month and year from a field
                    •   DATE_SUB(DATE, INTERVAL)
                        •Subtract a period of time from a date
Monday, July 25, 2011
Thank You
                                   Nicole C. Engard
                                  nengard@gmail.com

                        Slides: web2learning.net > Publications &
                                      Presentations

Monday, July 25, 2011
Ad

More Related Content

Viewers also liked (11)

Libraries Developing Openly
Libraries Developing OpenlyLibraries Developing Openly
Libraries Developing Openly
Nicole C. Engard
 
The New Age of Librarianship
The New Age of LibrarianshipThe New Age of Librarianship
The New Age of Librarianship
Nicole C. Engard
 
Open Source: Freedom and Community
Open Source: Freedom and CommunityOpen Source: Freedom and Community
Open Source: Freedom and Community
Nicole C. Engard
 
Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13
Nicole C. Engard
 
Practical Open Source Software for Libraries
Practical Open Source Software for LibrariesPractical Open Source Software for Libraries
Practical Open Source Software for Libraries
Nicole C. Engard
 
The Accidental Systems Librarian
The Accidental Systems LibrarianThe Accidental Systems Librarian
The Accidental Systems Librarian
Nicole C. Engard
 
Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...
Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...
Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...
Nicole C. Engard
 
Teaching and Learning Technology
Teaching and Learning TechnologyTeaching and Learning Technology
Teaching and Learning Technology
Nicole C. Engard
 
Web 2.0 Tools & Applications in Libraries
Web 2.0 Tools & Applications in LibrariesWeb 2.0 Tools & Applications in Libraries
Web 2.0 Tools & Applications in Libraries
Nicole C. Engard
 
Training on Koha
Training on KohaTraining on Koha
Training on Koha
Nicole C. Engard
 
Implementing Open Source
Implementing Open SourceImplementing Open Source
Implementing Open Source
Nicole C. Engard
 
Libraries Developing Openly
Libraries Developing OpenlyLibraries Developing Openly
Libraries Developing Openly
Nicole C. Engard
 
The New Age of Librarianship
The New Age of LibrarianshipThe New Age of Librarianship
The New Age of Librarianship
Nicole C. Engard
 
Open Source: Freedom and Community
Open Source: Freedom and CommunityOpen Source: Freedom and Community
Open Source: Freedom and Community
Nicole C. Engard
 
Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13
Nicole C. Engard
 
Practical Open Source Software for Libraries
Practical Open Source Software for LibrariesPractical Open Source Software for Libraries
Practical Open Source Software for Libraries
Nicole C. Engard
 
The Accidental Systems Librarian
The Accidental Systems LibrarianThe Accidental Systems Librarian
The Accidental Systems Librarian
Nicole C. Engard
 
Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...
Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...
Panning for Gold: Sifting through Emerging Technologies to Find the Real Trea...
Nicole C. Engard
 
Teaching and Learning Technology
Teaching and Learning TechnologyTeaching and Learning Technology
Teaching and Learning Technology
Nicole C. Engard
 
Web 2.0 Tools & Applications in Libraries
Web 2.0 Tools & Applications in LibrariesWeb 2.0 Tools & Applications in Libraries
Web 2.0 Tools & Applications in Libraries
Nicole C. Engard
 

Similar to Coding Potpourri: MySQL (20)

Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptx
QuyVo27
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
Polish SQL Server User Group
 
Windowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BIWindowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BI
Andrej Zafka
 
Inb343 week2 sql server intro
Inb343 week2 sql server introInb343 week2 sql server intro
Inb343 week2 sql server intro
Fredlive503
 
Database intro
Database introDatabase intro
Database intro
varsha nihanth lade
 
Excel basics for everyday use part two
Excel basics for everyday use part twoExcel basics for everyday use part two
Excel basics for everyday use part two
Kevin McLogan
 
Scaling with Riak at Showyou
Scaling with Riak at ShowyouScaling with Riak at Showyou
Scaling with Riak at Showyou
John Muellerleile
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
NilamHonmane
 
DP080_Lecture_1 SQL lecture document .pdf
DP080_Lecture_1 SQL lecture document .pdfDP080_Lecture_1 SQL lecture document .pdf
DP080_Lecture_1 SQL lecture document .pdf
MinhTran394436
 
SQL Tutorial
SQL TutorialSQL Tutorial
SQL Tutorial
ziamd
 
SQL
SQLSQL
SQL
kaushal123
 
SQL
SQLSQL
SQL
kaushal123
 
QSpiders - SQL (Data Base)
QSpiders - SQL (Data Base)QSpiders - SQL (Data Base)
QSpiders - SQL (Data Base)
Qspiders - Software Testing Training Institute
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf
jyothimuppasani1
 
Sql – pocket guide
Sql – pocket guideSql – pocket guide
Sql – pocket guide
Santhosh Kumar
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
ActiveRecord 2.3
ActiveRecord 2.3ActiveRecord 2.3
ActiveRecord 2.3
Reuven Lerner
 
P90 X Your Database!!
P90 X Your Database!!P90 X Your Database!!
P90 X Your Database!!
Denish Patel
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
Ike Ellis
 
Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptx
QuyVo27
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
Polish SQL Server User Group
 
Windowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BIWindowing functions session for Slovak SQL Pass & BI
Windowing functions session for Slovak SQL Pass & BI
Andrej Zafka
 
Inb343 week2 sql server intro
Inb343 week2 sql server introInb343 week2 sql server intro
Inb343 week2 sql server intro
Fredlive503
 
Excel basics for everyday use part two
Excel basics for everyday use part twoExcel basics for everyday use part two
Excel basics for everyday use part two
Kevin McLogan
 
Scaling with Riak at Showyou
Scaling with Riak at ShowyouScaling with Riak at Showyou
Scaling with Riak at Showyou
John Muellerleile
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
WrushabhShirsat3
 
DP080_Lecture_1 SQL lecture document .pdf
DP080_Lecture_1 SQL lecture document .pdfDP080_Lecture_1 SQL lecture document .pdf
DP080_Lecture_1 SQL lecture document .pdf
MinhTran394436
 
SQL Tutorial
SQL TutorialSQL Tutorial
SQL Tutorial
ziamd
 
•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf•Design (create) 3 questions for a quiz show game and design regular.pdf
•Design (create) 3 questions for a quiz show game and design regular.pdf
jyothimuppasani1
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
ColdFusionConference
 
P90 X Your Database!!
P90 X Your Database!!P90 X Your Database!!
P90 X Your Database!!
Denish Patel
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
Ike Ellis
 
Ad

More from Nicole C. Engard (17)

Intro to Wordpress
Intro to WordpressIntro to Wordpress
Intro to Wordpress
Nicole C. Engard
 
Open Source in Libraries: Freedom and Community
Open Source in Libraries: Freedom and CommunityOpen Source in Libraries: Freedom and Community
Open Source in Libraries: Freedom and Community
Nicole C. Engard
 
Open Source Tools for Libraries
Open Source Tools for LibrariesOpen Source Tools for Libraries
Open Source Tools for Libraries
Nicole C. Engard
 
Using Wordpress To Create Your Website
Using Wordpress To Create Your WebsiteUsing Wordpress To Create Your Website
Using Wordpress To Create Your Website
Nicole C. Engard
 
Open Source for Libraries
Open Source for LibrariesOpen Source for Libraries
Open Source for Libraries
Nicole C. Engard
 
Why Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & LibrariansWhy Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & Librarians
Nicole C. Engard
 
Open Source Software for Libraries
Open Source Software for LibrariesOpen Source Software for Libraries
Open Source Software for Libraries
Nicole C. Engard
 
Koha: Participation is Key
Koha: Participation is KeyKoha: Participation is Key
Koha: Participation is Key
Nicole C. Engard
 
Intoduction to Koha Technical Services
Intoduction to Koha Technical ServicesIntoduction to Koha Technical Services
Intoduction to Koha Technical Services
Nicole C. Engard
 
Koha Advanced Functions
Koha Advanced FunctionsKoha Advanced Functions
Koha Advanced Functions
Nicole C. Engard
 
Why Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & LibrariansWhy Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & Librarians
Nicole C. Engard
 
Providing Services to our Remote Users: Open Source Solutions
Providing Services to our Remote Users: Open Source SolutionsProviding Services to our Remote Users: Open Source Solutions
Providing Services to our Remote Users: Open Source Solutions
Nicole C. Engard
 
Practical Open Source Software for Libraries (part 2)
Practical Open Source Software for Libraries (part 2)Practical Open Source Software for Libraries (part 2)
Practical Open Source Software for Libraries (part 2)
Nicole C. Engard
 
Practical Open Source Software for Libraries (part 1)
Practical Open Source Software for Libraries (part 1)Practical Open Source Software for Libraries (part 1)
Practical Open Source Software for Libraries (part 1)
Nicole C. Engard
 
Operating on a Budget: Ubuntu for Libraries
Operating on a Budget: Ubuntu for LibrariesOperating on a Budget: Ubuntu for Libraries
Operating on a Budget: Ubuntu for Libraries
Nicole C. Engard
 
Open Source Technology for Libraries
Open Source Technology for LibrariesOpen Source Technology for Libraries
Open Source Technology for Libraries
Nicole C. Engard
 
Library mashups: Exploring new ways to deliver library data
Library mashups: Exploring new ways to deliver library dataLibrary mashups: Exploring new ways to deliver library data
Library mashups: Exploring new ways to deliver library data
Nicole C. Engard
 
Open Source in Libraries: Freedom and Community
Open Source in Libraries: Freedom and CommunityOpen Source in Libraries: Freedom and Community
Open Source in Libraries: Freedom and Community
Nicole C. Engard
 
Open Source Tools for Libraries
Open Source Tools for LibrariesOpen Source Tools for Libraries
Open Source Tools for Libraries
Nicole C. Engard
 
Using Wordpress To Create Your Website
Using Wordpress To Create Your WebsiteUsing Wordpress To Create Your Website
Using Wordpress To Create Your Website
Nicole C. Engard
 
Why Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & LibrariansWhy Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & Librarians
Nicole C. Engard
 
Open Source Software for Libraries
Open Source Software for LibrariesOpen Source Software for Libraries
Open Source Software for Libraries
Nicole C. Engard
 
Koha: Participation is Key
Koha: Participation is KeyKoha: Participation is Key
Koha: Participation is Key
Nicole C. Engard
 
Intoduction to Koha Technical Services
Intoduction to Koha Technical ServicesIntoduction to Koha Technical Services
Intoduction to Koha Technical Services
Nicole C. Engard
 
Why Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & LibrariansWhy Should I Care? New Technologies for Libraries & Librarians
Why Should I Care? New Technologies for Libraries & Librarians
Nicole C. Engard
 
Providing Services to our Remote Users: Open Source Solutions
Providing Services to our Remote Users: Open Source SolutionsProviding Services to our Remote Users: Open Source Solutions
Providing Services to our Remote Users: Open Source Solutions
Nicole C. Engard
 
Practical Open Source Software for Libraries (part 2)
Practical Open Source Software for Libraries (part 2)Practical Open Source Software for Libraries (part 2)
Practical Open Source Software for Libraries (part 2)
Nicole C. Engard
 
Practical Open Source Software for Libraries (part 1)
Practical Open Source Software for Libraries (part 1)Practical Open Source Software for Libraries (part 1)
Practical Open Source Software for Libraries (part 1)
Nicole C. Engard
 
Operating on a Budget: Ubuntu for Libraries
Operating on a Budget: Ubuntu for LibrariesOperating on a Budget: Ubuntu for Libraries
Operating on a Budget: Ubuntu for Libraries
Nicole C. Engard
 
Open Source Technology for Libraries
Open Source Technology for LibrariesOpen Source Technology for Libraries
Open Source Technology for Libraries
Nicole C. Engard
 
Library mashups: Exploring new ways to deliver library data
Library mashups: Exploring new ways to deliver library dataLibrary mashups: Exploring new ways to deliver library data
Library mashups: Exploring new ways to deliver library data
Nicole C. Engard
 
Ad

Recently uploaded (20)

tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
How analogue intelligence complements AI
How analogue intelligence complements AIHow analogue intelligence complements AI
How analogue intelligence complements AI
Paul Rowe
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Web and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in RajpuraWeb and Graphics Designing Training in Rajpura
Web and Graphics Designing Training in Rajpura
Erginous Technology
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdfAre Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Are Cloud PBX Providers in India Reliable for Small Businesses (1).pdf
Telecoms Supermarket
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Social Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTechSocial Media App Development Company-EmizenTech
Social Media App Development Company-EmizenTech
Steve Jonas
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 

Coding Potpourri: MySQL

  • 1. Coding Potpourri: MySQL Nicole C. Engard Director of Open Source Education, ByWater Solutions Author of Practical Open Source Software for Libraries Monday, July 25, 2011
  • 2. My What? • MySQL: My Structured Query Language • Relational Database Management System • Licensed with the GNU GPL • That means it’s Open Source • Used to organize data in a structured way Monday, July 25, 2011
  • 3. Who’s Using It? • MySQL is the database behind many popular web based applications • Wordpress • YouTube • Drupal • Flickr • Wikipedia • Ebay • Facebook • Google (not searches) Monday, July 25, 2011
  • 4. Reading Table Structure CREATE TABLE `branches` ( `branchcode` varchar(10) NOT NULL default '', `branchname` mediumtext NOT NULL, `branchaddress1` mediumtext, `branchaddress2` mediumtext, `branchaddress3` mediumtext, `branchphone` mediumtext, `branchfax` mediumtext, `branchemail` mediumtext, UNIQUE KEY `branchcode` (`branchcode`) ) Monday, July 25, 2011
  • 5. Reading Table Structure • This table’s name is ‘branches’ and it stores the information about libraries or branches in Koha. • Each field is easy to identify because of its name (ex. branchname is the library name). • A field with a number in parens after it is a field that is limited in size. • For example varchar(10) means the field can have no more than 10 characters in it • Lastly, we see that ‘branchcode’ is the unique key or unique identifier in the table. Monday, July 25, 2011
  • 6. Inserting Data • Using the branches table enter a branch’s info INSERT INTO branches (branchcode, branchname, branchaddress1, branchaddress2, branchphone, branchemail) VALUES (‘LIB’, ‘My Library’, ‘123 Library Road’, ‘Philadelphia, PA’, ‘215.555.1234’, ‘[email protected]’); Monday, July 25, 2011
  • 7. Querying MySQL • To query a single table you will structure your query like this: • SELECT column_names FROM table_name [WHERE ...conditions] [ORDER BY ...conditions]; • Statements in brackets are optional • You can also select everything in a table by using an * in place of column_names Monday, July 25, 2011
  • 8. Querying MySQL • Using the branches table let’s query the data • This query will pull out only the Branch Names and Emails and put them in ascending order by name SELECT branchname, branchemail FROM branches ORDER BY branchname ASC; Monday, July 25, 2011
  • 9. Querying MySQL • Using branches let’s get the address info from one specific branch SELECT branchname, branchaddress1, branchaddress2, branchaddress3, branchemail FROM branches WHERE branchcode=‘LIB’; Monday, July 25, 2011
  • 10. Querying MySQL • Using branches let’s pull out the branch’s phone and fax in one column SELECT CONCAT(‘ph. ’, branchphone, ‘ fax ’, branchfax) as ‘contact info’ FROM branches WHERE branchcode= ‘LIB’; Monday, July 25, 2011
  • 11. Another Table CREATE TABLE `issues` ( `borrowernumber` int(11) default NULL, `itemnumber` int(11) default NULL, `date_due` date default NULL, `branchcode` varchar(10) default NULL, `returndate` date default NULL, `return` varchar(4) default NULL, `renewals` tinyint(4) default NULL, `issuedate` date default NULL, KEY `issuesborridx` (`borrowernumber`), KEY `issuesitemidx` (`itemnumber`), ) Monday, July 25, 2011
  • 12. Joining Tables • Using branches and issues let’s find out how many items circulated at each branch in a specific time period SELECT b.branchname, count(i.branchcode) as count FROM issues i LEFT JOIN branches b ON (i.branchcode=b.branchcode) WHERE i.issuedate BETWEEN ‘2011-06-01’ AND ‘2011-07-01’ GROUP BY b.branchcode ORDER BY count DESC; Monday, July 25, 2011
  • 13. Date & Time Functions • The most common use for reports is for end of the month or end of the year statistics • The MySQL manual on Date & Time functions is essential for these queries • http://dev.mysql.com/doc/refman/5.6/en/ date-and-time-functions.html Monday, July 25, 2011
  • 14. String Functions • Often you want to join two or more strings together, find a part of a string or even change a part of a string • String functions are defined in the MySQL manual • http://dev.mysql.com/doc/refman/5.6/en/ string-functions.html Monday, July 25, 2011
  • 15. Math Functions • Using MySQL you can get fancy with statistics by using the number related functions • The Numeric Functions section of the manual can help you here • http://dev.mysql.com/doc/refman/5.6/en/ numeric-functions.html Monday, July 25, 2011
  • 16. Common Functions • COUNT(FIELD) or SUM(FIELD) •Counts the number of or adds up the total value of results in a column • CURDATE() •Is the current date (not time, just date) • MONTH(FIELD) and YEAR(FIELD) •Return the month and year from a field • DATE_SUB(DATE, INTERVAL) •Subtract a period of time from a date Monday, July 25, 2011
  • 17. Thank You Nicole C. Engard [email protected] Slides: web2learning.net > Publications & Presentations Monday, July 25, 2011