SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Andere mochten auch

Libraries Developing Openly
Libraries Developing OpenlyLibraries Developing Openly
Libraries Developing OpenlyNicole C. Engard
 
The New Age of Librarianship
The New Age of LibrarianshipThe New Age of Librarianship
The New Age of LibrarianshipNicole C. Engard
 
Open Source: Freedom and Community
Open Source: Freedom and CommunityOpen Source: Freedom and Community
Open Source: Freedom and CommunityNicole C. Engard
 
Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13Nicole C. Engard
 
Practical Open Source Software for Libraries
Practical Open Source Software for LibrariesPractical Open Source Software for Libraries
Practical Open Source Software for LibrariesNicole C. Engard
 
The Accidental Systems Librarian
The Accidental Systems LibrarianThe Accidental Systems Librarian
The Accidental Systems LibrarianNicole 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 TechnologyNicole 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 LibrariesNicole C. Engard
 

Andere mochten auch (11)

Libraries Developing Openly
Libraries Developing OpenlyLibraries Developing Openly
Libraries Developing Openly
 
The New Age of Librarianship
The New Age of LibrarianshipThe New Age of Librarianship
The New Age of Librarianship
 
Open Source: Freedom and Community
Open Source: Freedom and CommunityOpen Source: Freedom and Community
Open Source: Freedom and Community
 
Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13Training Koha Libraries - KohaCon13
Training Koha Libraries - KohaCon13
 
Practical Open Source Software for Libraries
Practical Open Source Software for LibrariesPractical Open Source Software for Libraries
Practical Open Source Software for Libraries
 
The Accidental Systems Librarian
The Accidental Systems LibrarianThe Accidental Systems Librarian
The Accidental Systems Librarian
 
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...
 
Teaching and Learning Technology
Teaching and Learning TechnologyTeaching and Learning Technology
Teaching and Learning Technology
 
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
 
Training on Koha
Training on KohaTraining on Koha
Training on Koha
 
Implementing Open Source
Implementing Open SourceImplementing Open Source
Implementing Open Source
 

Ähnlich wie Coding Potpourri: MySQL

Querying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuerying_with_T-SQL_-_01.pptx
Querying_with_T-SQL_-_01.pptxQuyVo27
 
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 DeveloperPolish 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 & BIAndrej Zafka
 
Inb343 week2 sql server intro
Inb343 week2 sql server introInb343 week2 sql server intro
Inb343 week2 sql server introFredlive503
 
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 twoKevin McLogan
 
Scaling with Riak at Showyou
Scaling with Riak at ShowyouScaling with Riak at Showyou
Scaling with Riak at ShowyouJohn Muellerleile
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytWrushabhShirsat3
 
SQL Tutorial
SQL TutorialSQL Tutorial
SQL Tutorialziamd
 
•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.pdfjyothimuppasani1
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
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.pptxIke Ellis
 

Ähnlich wie 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
 
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
 
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
 
Inb343 week2 sql server intro
Inb343 week2 sql server introInb343 week2 sql server intro
Inb343 week2 sql server intro
 
Database intro
Database introDatabase intro
Database intro
 
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
 
Scaling with Riak at Showyou
Scaling with Riak at ShowyouScaling with Riak at Showyou
Scaling with Riak at Showyou
 
unit-ii.pptx
unit-ii.pptxunit-ii.pptx
unit-ii.pptx
 
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfytxjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
xjtrutdctrd5454drxxresersestryugyufy6rythgfytfyt
 
SQL
SQLSQL
SQL
 
SQL
SQLSQL
SQL
 
SQL Tutorial
SQL TutorialSQL Tutorial
SQL Tutorial
 
QSpiders - SQL (Data Base)
QSpiders - SQL (Data Base)QSpiders - SQL (Data Base)
QSpiders - SQL (Data Base)
 
•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
 
Sql – pocket guide
Sql – pocket guideSql – pocket guide
Sql – pocket guide
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
ActiveRecord 2.3
ActiveRecord 2.3ActiveRecord 2.3
ActiveRecord 2.3
 
P90 X Your Database!!
P90 X Your Database!!P90 X Your Database!!
P90 X Your Database!!
 
Build a modern data platform.pptx
Build a modern data platform.pptxBuild a modern data platform.pptx
Build a modern data platform.pptx
 
Oracle 11g sql plsql training
Oracle 11g sql plsql trainingOracle 11g sql plsql training
Oracle 11g sql plsql training
 

Mehr von 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 CommunityNicole C. Engard
 
Open Source Tools for Libraries
Open Source Tools for LibrariesOpen Source Tools for Libraries
Open Source Tools for LibrariesNicole C. Engard
 
Using Wordpress To Create Your Website
Using Wordpress To Create Your WebsiteUsing Wordpress To Create Your Website
Using Wordpress To Create Your WebsiteNicole 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 & LibrariansNicole C. Engard
 
Open Source Software for Libraries
Open Source Software for LibrariesOpen Source Software for Libraries
Open Source Software for LibrariesNicole C. Engard
 
Koha: Participation is Key
Koha: Participation is KeyKoha: Participation is Key
Koha: Participation is KeyNicole C. Engard
 
Intoduction to Koha Technical Services
Intoduction to Koha Technical ServicesIntoduction to Koha Technical Services
Intoduction to Koha Technical ServicesNicole 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 & LibrariansNicole 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 SolutionsNicole 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 LibrariesNicole C. Engard
 
Open Source Technology for Libraries
Open Source Technology for LibrariesOpen Source Technology for Libraries
Open Source Technology for LibrariesNicole 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 dataNicole C. Engard
 

Mehr von Nicole C. Engard (17)

Intro to Wordpress
Intro to WordpressIntro to Wordpress
Intro to Wordpress
 
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
 
Open Source Tools for Libraries
Open Source Tools for LibrariesOpen Source Tools for Libraries
Open Source Tools for Libraries
 
Using Wordpress To Create Your Website
Using Wordpress To Create Your WebsiteUsing Wordpress To Create Your Website
Using Wordpress To Create Your Website
 
Open Source for Libraries
Open Source for LibrariesOpen Source for Libraries
Open Source for Libraries
 
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
 
Open Source Software for Libraries
Open Source Software for LibrariesOpen Source Software for Libraries
Open Source Software for Libraries
 
Koha: Participation is Key
Koha: Participation is KeyKoha: Participation is Key
Koha: Participation is Key
 
Intoduction to Koha Technical Services
Intoduction to Koha Technical ServicesIntoduction to Koha Technical Services
Intoduction to Koha Technical Services
 
Koha Advanced Functions
Koha Advanced FunctionsKoha Advanced Functions
Koha Advanced Functions
 
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
 
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
 
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)
 
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)
 
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
 
Open Source Technology for Libraries
Open Source Technology for LibrariesOpen Source Technology for Libraries
Open Source Technology for Libraries
 
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
 

Kürzlich hochgeladen

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

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’, ‘info@library.com’); 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 nengard@gmail.com Slides: web2learning.net > Publications & Presentations Monday, July 25, 2011