SlideShare uma empresa Scribd logo
1 de 30
INTRODUCTION TO SQL
BOOTHTECH
JENNIFER BERK, MAY 2012
AGENDA
• What's SQL and when would you use it
• How to find out what's in your database
• How to pull the information you need, with
progressively more realistic exercises
• How to learn more
• Questions and more practice time
• Note: specific syntax today is for MySQL, but any
database will be similar
WHAT IS SQL?
A N D WH Y I T ’ S U S E F U L T O A N M B A
RELATIONAL DATABASE

Billing
address
has an

Date
placed
Shipping
method
containing

Item

Contact
name

Order

Client

• Stores data in a series of tables
• Also stores information about relationships between
data in tables (hence relational)
Item
number
Quantity
Size
Color
WHAT KIND OF DATA?
• Numeric
• Integers with various possible ranges (sometimes TRUE/FALSE
Boolean values are encoded as 0/1 in an integer field) - INT
• Decimals or floating-point numbers – FLOAT

• Time and date - DATETIME
• Text
• With a specified length in characters – VARCHAR
• Longer text – TEXT

• Binary data – BLOB
WHY USE A RELATIONAL
DATABASE
• Think about a list of contacts in Excel – basically one
database table – and adding a phone number.
• Do you have enough phone number columns?
• Does cell phone have its own field or is it just
another phone number?
• How do you mark the primary phone number?
• A database lets you have as many phone numbers
as you want associated with one person, because
you can put phone numbers in a separate table.
STRUCTURED QUERY LANGUAGE
• SQL is a way to pull the information you need out of
a relational database
• You’ll probably use it to fetch summary information
from a central data warehouse and then do
additional analysis in Excel/SAS/etc.
• SQL is also used (by the people who set up the data
warehouse) to create tables, insert data, and
delete unneeded information.
SANDBOX
1. Take out your laptop
2. Go to http://coderzone.org/sqlsandbox/
3. Click “Sign In”
WHAT’S IN YOUR DATABASE?
SHOW TABLES; DESCRIBE <TABLENAME>;
SHOW TABLES;
• Returns a list of tables in the database
• May not need to use this if you have a graphical
user interface (GUI)
• Can limit which tables are returned, e.g. “SHOW
TABLES LIKE ‘%c%’;” will return all the tables with a
“c” in their name
DESCRIBE <TABLENAME>;
• Returns information about each field in table
<tablename>
• Includes field name, type, and other information like
if the field can be NULL or if it’s required to have a
value
• May not need to use this if you have a graphical
user interface (GUI)
TRY IT OUT
• In the sandbox, try looking at tables.
• SHOW TABLES [LIKE “%c%”];
• DESCRIBE sb_css_colors;
• Which tables contain the most types of data?
SQL STYLE
• Capitalize SQL keywords (SELECT, JOIN, AS, etc.)
• Lower-case table and field names
Makes it easy to see what values are specific to the
database you’re using.
BASIC DATA SELECTION
SELECT <FIELDS> FROM <TABLENAME>;
SELECT <FIELDS> FROM <TABLENAME>;
• Returns some data from a table
• You’ll need the field names you found before from
the DESCRIBE <tablename> statement
• <fields> can be:
•
•
•
•

One field name
Multiple field names separated by commas
Special value * (asterisk), which means “everything”
Special value COUNT(*), which means “how many rows are
there?”

• This returns all the rows of the table – why might that
be a problem?
TRY IT OUT
• In the sandbox, try looking at some data in tables.
• SELECT * FROM sb_css_colors;
• SELECT COUNT(*) FROM sb_airports;
• SELECT biz_name, state, phone FROM sb_airports;
LIMITING DATA SELECTION
SELECT <FI ELDS> FROM < TABLENAME> WHERE <LI MITS> ;
WHERE
• SELECT <fields> FROM <tablename> WHERE <limits> ;
• This is how to start picking out only the data you’re
interested in
• WHERE clauses can be:
• <fieldname> = <value> such as 2 or “Bob”
• Similar but with LIKE, >, >=, <, <=, != (note that different SQL
implementations require different representations for
dates/times, so you may have to check documentation to
figure out how to say purchase_date > “2012-01-01”, for
example)
• Things involving functions, like ABS(<fieldname>) > 20
• Several of those joined by AND, OR, etc.
TRY IT OUT
• In the sandbox, try limiting what data you grab.
• SELECT * FROM sb_css_colors WHERE
hexcolor=“#800000”
• SELECT * FROM sb_css_colors WHERE hexcolor LIKE
“%FF%”
• SELECT biz_name, state, zip, phone FROM
sb_airports WHERE (state=“IL” OR state=“IN”) AND
phone LIKE “%(800)%”;
MORE DATA SELECTION
SELECT <FIELDS> FROM < TABLENAME> WHERE <LIMITS>
ORDER BY <FIELD> <ORDER> GROUP BY <FIELD>;
ORDER BY
• SELECT <fields> FROM <tablename> ORDER BY
<field> <order>;
• Like sorting in Excel
• Order can be ASC (ascending) or DESC
(descending)
• Don’t sort and then assume you know what the
possible values were – e.g. what’s at the top if you
do SELECT * FROM sb_css_colors ORDER BY hexcolor
DESC;
GROUP BY
• SELECT <fields and/or functions of fields> FROM
<tablename> GROUP BY <field>;
• Lets you create summary statistics directly instead of
in Excel later
• Commonly used functions: COUNT(),
COUNT(DISTINCT), SUM(), AVG(), MAX(), MIN(),
TRY IT OUT
• In the sandbox, try more complicated SELECTs.
• SELECT * FROM sb_css_colors ORDER BY hexcolor
DESC; (what were the possible values?)
• SELECT state, zip, COUNT(*) from sb_airports GROUP
BY zip;
• SELECT state, AVG(zip) FROM sb_airports GROUP BY
state;
CONNECTING TABLES: JOINS
SELECT <FIELDS> FROM <TABLENAME> JOIN
<TABLENAME> ON <FIELD MATCH>;
JOIN
• SELECT <fields> FROM <tablename> JOIN
<tablename> ON <field match>;
• Joins let you connect related data from multiple
tables, e.g. a customer name from a customers
table and an order date from an orders table
• Normally you’ll join on an ID or “key” column
• Often need to specify both table and field when
writing the field match statement
• customers.id = orders.customer_id
TRY IT OUT
• In the sandbox, try joining tables.
• SELECT comp_dept, first_name, last_name, phone
FROM sb_departments JOIN sb_employees ON
sb_departments.emp_id = sb_employees.emp_id
WHERE comp_dept = “Payroll”;
HOW TO LEARN MORE
USEFUL RESOURCES
ONLINE RESOURCES
• MySQL manuals (MySQL is open source, so there are
lots of resources freely available)
• http://dev.mysql.com/doc/refman/5.6/en/index.html

• Question sites:
• http://www.quora.com/MySQL/
• http://programmers.stackexchange.com/questions/tagged
/sql (pretty technical in general)
SANDBOXES
• We’ve used http://coderzone.org/sqlsandbox/
(nice because it has multiple tables)
• Also http://www.w3schools.com/sql/default.asp
• You can make your own sandbox to try things out if
you have web hosting (e.g. unlimited MySQL
databases on DreamHost)
QUESTIONS?
AND MORE PRACTICE TIME

Mais conteúdo relacionado

Mais procurados

DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleFarhan Aslam
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)Nalina Kumari
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)Sabana Maharjan
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLMahir Haque
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLEhsan Hamzei
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 
SQL Queries
SQL QueriesSQL Queries
SQL QueriesNilt1234
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sqlNazir Ahmed
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLPrashant Kumar
 

Mais procurados (19)

DDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using OracleDDL(Data defination Language ) Using Oracle
DDL(Data defination Language ) Using Oracle
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sql
 
Introduction to (sql)
Introduction to (sql)Introduction to (sql)
Introduction to (sql)
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQLSql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Create table
Create tableCreate table
Create table
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 

Semelhante a Introduction to SQL (for Chicago Booth MBA technology club)

Semelhante a Introduction to SQL (for Chicago Booth MBA technology club) (20)

SQL
SQLSQL
SQL
 
Tk2323 lecture 7 sql
Tk2323 lecture 7   sql Tk2323 lecture 7   sql
Tk2323 lecture 7 sql
 
SQL_Part1
SQL_Part1SQL_Part1
SQL_Part1
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 
php basic sql
php basic sqlphp basic sql
php basic sql
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Rdbms day3
Rdbms day3Rdbms day3
Rdbms day3
 
SQL Reports in Koha
SQL Reports in KohaSQL Reports in Koha
SQL Reports in Koha
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Sql
SqlSql
Sql
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
ORACLE PL SQL
ORACLE PL SQLORACLE PL SQL
ORACLE PL SQL
 
Access 04
Access 04Access 04
Access 04
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Module 3
Module 3Module 3
Module 3
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Apache TAJO
Apache TAJOApache TAJO
Apache TAJO
 
Database
Database Database
Database
 
Sql introduction
Sql introductionSql introduction
Sql introduction
 

Mais de Jennifer Berk

Chicago Booth MBA application presentation (2010)
Chicago Booth MBA application presentation (2010)Chicago Booth MBA application presentation (2010)
Chicago Booth MBA application presentation (2010)Jennifer Berk
 
Minimum Viable Project Management
Minimum Viable Project ManagementMinimum Viable Project Management
Minimum Viable Project ManagementJennifer Berk
 
Twitter For Nonprofits
Twitter For NonprofitsTwitter For Nonprofits
Twitter For NonprofitsJennifer Berk
 
Social Media At Work
Social Media At WorkSocial Media At Work
Social Media At WorkJennifer Berk
 
What I Learned on My Fall Vacation
What I Learned on My Fall VacationWhat I Learned on My Fall Vacation
What I Learned on My Fall VacationJennifer Berk
 
Content Cross-promotion
Content Cross-promotionContent Cross-promotion
Content Cross-promotionJennifer Berk
 

Mais de Jennifer Berk (7)

Chicago Booth MBA application presentation (2010)
Chicago Booth MBA application presentation (2010)Chicago Booth MBA application presentation (2010)
Chicago Booth MBA application presentation (2010)
 
Minimum Viable Project Management
Minimum Viable Project ManagementMinimum Viable Project Management
Minimum Viable Project Management
 
CSS 201
CSS 201CSS 201
CSS 201
 
Twitter For Nonprofits
Twitter For NonprofitsTwitter For Nonprofits
Twitter For Nonprofits
 
Social Media At Work
Social Media At WorkSocial Media At Work
Social Media At Work
 
What I Learned on My Fall Vacation
What I Learned on My Fall VacationWhat I Learned on My Fall Vacation
What I Learned on My Fall Vacation
 
Content Cross-promotion
Content Cross-promotionContent Cross-promotion
Content Cross-promotion
 

Último

Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...lizamodels9
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1kcpayne
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityEric T. Tung
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwaitdaisycvs
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000dlhescort
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Sheetaleventcompany
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentationuneakwhite
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture conceptP&CO
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...allensay1
 
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLJAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLkapoorjyoti4444
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876dlhescort
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876dlhescort
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...amitlee9823
 
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceDamini Dixit
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...lizamodels9
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...rajveerescorts2022
 

Último (20)

Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024Marel Q1 2024 Investor Presentation from May 8, 2024
Marel Q1 2024 Investor Presentation from May 8, 2024
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
Call Girls In Majnu Ka Tilla 959961~3876 Shot 2000 Night 8000
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRLJAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
JAYNAGAR CALL GIRL IN 98274*61493 ❤CALL GIRLS IN ESCORT SERVICE❤CALL GIRL
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceMalegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Malegaon Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
 
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 

Introduction to SQL (for Chicago Booth MBA technology club)

  • 2. AGENDA • What's SQL and when would you use it • How to find out what's in your database • How to pull the information you need, with progressively more realistic exercises • How to learn more • Questions and more practice time • Note: specific syntax today is for MySQL, but any database will be similar
  • 3. WHAT IS SQL? A N D WH Y I T ’ S U S E F U L T O A N M B A
  • 4. RELATIONAL DATABASE Billing address has an Date placed Shipping method containing Item Contact name Order Client • Stores data in a series of tables • Also stores information about relationships between data in tables (hence relational) Item number Quantity Size Color
  • 5. WHAT KIND OF DATA? • Numeric • Integers with various possible ranges (sometimes TRUE/FALSE Boolean values are encoded as 0/1 in an integer field) - INT • Decimals or floating-point numbers – FLOAT • Time and date - DATETIME • Text • With a specified length in characters – VARCHAR • Longer text – TEXT • Binary data – BLOB
  • 6. WHY USE A RELATIONAL DATABASE • Think about a list of contacts in Excel – basically one database table – and adding a phone number. • Do you have enough phone number columns? • Does cell phone have its own field or is it just another phone number? • How do you mark the primary phone number? • A database lets you have as many phone numbers as you want associated with one person, because you can put phone numbers in a separate table.
  • 7. STRUCTURED QUERY LANGUAGE • SQL is a way to pull the information you need out of a relational database • You’ll probably use it to fetch summary information from a central data warehouse and then do additional analysis in Excel/SAS/etc. • SQL is also used (by the people who set up the data warehouse) to create tables, insert data, and delete unneeded information.
  • 8. SANDBOX 1. Take out your laptop 2. Go to http://coderzone.org/sqlsandbox/ 3. Click “Sign In”
  • 9. WHAT’S IN YOUR DATABASE? SHOW TABLES; DESCRIBE <TABLENAME>;
  • 10. SHOW TABLES; • Returns a list of tables in the database • May not need to use this if you have a graphical user interface (GUI) • Can limit which tables are returned, e.g. “SHOW TABLES LIKE ‘%c%’;” will return all the tables with a “c” in their name
  • 11. DESCRIBE <TABLENAME>; • Returns information about each field in table <tablename> • Includes field name, type, and other information like if the field can be NULL or if it’s required to have a value • May not need to use this if you have a graphical user interface (GUI)
  • 12. TRY IT OUT • In the sandbox, try looking at tables. • SHOW TABLES [LIKE “%c%”]; • DESCRIBE sb_css_colors; • Which tables contain the most types of data?
  • 13. SQL STYLE • Capitalize SQL keywords (SELECT, JOIN, AS, etc.) • Lower-case table and field names Makes it easy to see what values are specific to the database you’re using.
  • 14. BASIC DATA SELECTION SELECT <FIELDS> FROM <TABLENAME>;
  • 15. SELECT <FIELDS> FROM <TABLENAME>; • Returns some data from a table • You’ll need the field names you found before from the DESCRIBE <tablename> statement • <fields> can be: • • • • One field name Multiple field names separated by commas Special value * (asterisk), which means “everything” Special value COUNT(*), which means “how many rows are there?” • This returns all the rows of the table – why might that be a problem?
  • 16. TRY IT OUT • In the sandbox, try looking at some data in tables. • SELECT * FROM sb_css_colors; • SELECT COUNT(*) FROM sb_airports; • SELECT biz_name, state, phone FROM sb_airports;
  • 17. LIMITING DATA SELECTION SELECT <FI ELDS> FROM < TABLENAME> WHERE <LI MITS> ;
  • 18. WHERE • SELECT <fields> FROM <tablename> WHERE <limits> ; • This is how to start picking out only the data you’re interested in • WHERE clauses can be: • <fieldname> = <value> such as 2 or “Bob” • Similar but with LIKE, >, >=, <, <=, != (note that different SQL implementations require different representations for dates/times, so you may have to check documentation to figure out how to say purchase_date > “2012-01-01”, for example) • Things involving functions, like ABS(<fieldname>) > 20 • Several of those joined by AND, OR, etc.
  • 19. TRY IT OUT • In the sandbox, try limiting what data you grab. • SELECT * FROM sb_css_colors WHERE hexcolor=“#800000” • SELECT * FROM sb_css_colors WHERE hexcolor LIKE “%FF%” • SELECT biz_name, state, zip, phone FROM sb_airports WHERE (state=“IL” OR state=“IN”) AND phone LIKE “%(800)%”;
  • 20. MORE DATA SELECTION SELECT <FIELDS> FROM < TABLENAME> WHERE <LIMITS> ORDER BY <FIELD> <ORDER> GROUP BY <FIELD>;
  • 21. ORDER BY • SELECT <fields> FROM <tablename> ORDER BY <field> <order>; • Like sorting in Excel • Order can be ASC (ascending) or DESC (descending) • Don’t sort and then assume you know what the possible values were – e.g. what’s at the top if you do SELECT * FROM sb_css_colors ORDER BY hexcolor DESC;
  • 22. GROUP BY • SELECT <fields and/or functions of fields> FROM <tablename> GROUP BY <field>; • Lets you create summary statistics directly instead of in Excel later • Commonly used functions: COUNT(), COUNT(DISTINCT), SUM(), AVG(), MAX(), MIN(),
  • 23. TRY IT OUT • In the sandbox, try more complicated SELECTs. • SELECT * FROM sb_css_colors ORDER BY hexcolor DESC; (what were the possible values?) • SELECT state, zip, COUNT(*) from sb_airports GROUP BY zip; • SELECT state, AVG(zip) FROM sb_airports GROUP BY state;
  • 24. CONNECTING TABLES: JOINS SELECT <FIELDS> FROM <TABLENAME> JOIN <TABLENAME> ON <FIELD MATCH>;
  • 25. JOIN • SELECT <fields> FROM <tablename> JOIN <tablename> ON <field match>; • Joins let you connect related data from multiple tables, e.g. a customer name from a customers table and an order date from an orders table • Normally you’ll join on an ID or “key” column • Often need to specify both table and field when writing the field match statement • customers.id = orders.customer_id
  • 26. TRY IT OUT • In the sandbox, try joining tables. • SELECT comp_dept, first_name, last_name, phone FROM sb_departments JOIN sb_employees ON sb_departments.emp_id = sb_employees.emp_id WHERE comp_dept = “Payroll”;
  • 27. HOW TO LEARN MORE USEFUL RESOURCES
  • 28. ONLINE RESOURCES • MySQL manuals (MySQL is open source, so there are lots of resources freely available) • http://dev.mysql.com/doc/refman/5.6/en/index.html • Question sites: • http://www.quora.com/MySQL/ • http://programmers.stackexchange.com/questions/tagged /sql (pretty technical in general)
  • 29. SANDBOXES • We’ve used http://coderzone.org/sqlsandbox/ (nice because it has multiple tables) • Also http://www.w3schools.com/sql/default.asp • You can make your own sandbox to try things out if you have web hosting (e.g. unlimited MySQL databases on DreamHost)