SlideShare una empresa de Scribd logo
1 de 32
MySQL Basics
Jamshid Hashimi
Trainer, Cresco Solution
http://www.jamshidhashimi.com
jamshid@netlinks.af
@jamshidhashimi
ajamshidhashimi
Afghanistan Workforce
Development Program
Agenda
• Introduction MySQL
• Simple Select
• MySQL Connect
• Comments
• Whitespace and Semi-colons
• Case Sensitivity
• SELECTing All Columns in All Rows
• SELECTing Specific Columns
• Sorting Records
• Sorting By a Single Column
• Sorting By Multiple Columns
• Sorting By Column Position
Agenda
• Ascending and Descending Sorts
• The WHERE Clause and Operator Symbols
• Checking for Equality
• Checking for Inequality
• Checking for Greater or Less Than
• Checking for NULL
• The WHERE Clause and Operator Words
• The BETWEEN Operator
• The IN Operator
• The LIKE Operator
• The NOT Operator
• Checking Multiple Conditions
• AND, OR, Order of Evaluation
Introduction MySQL
• MySQL is a fast, easy-to-use RDBMS used being used for many small
and big businesses. MySQL was owned and sponsored by a single
for-profit firm, the Swedish company MySQL AB, now owned by
Oracle Corporation. MySQL is becoming so popular because of
many good reasons.
• MySQL is released under an open-source license. So you have
nothing to pay to use it.
• MySQL is a very powerful program in its own right. It handles a
large subset of the functionality of the most expensive and
powerful database packages.
• MySQL uses a standard form of the well-known SQL data language.
• MySQL works on many operating systems and with many languages
including PHP, PERL, C, C++, JAVA etc.
Introduction to MySQL
• MySQL works very quickly and works well even with
large data sets.
• MySQL is very friendly to PHP, the most appreciated
language for web development.
• MySQL supports large databases, up to 50 million rows
or more in a table. The default file size limit for a table
is 4GB, but you can increase this (if your operating
system can handle it) to a theoretical limit of 8 million
terabytes (TB).
• MySQL is customizable. The open source GPL license
allows programmers to modify the MySQL software to
fit their own specific environments.
Simple SELECT
• A query is a question or a request
SELECT last_name FROM employees
MySQL Connect
• Use the PHP mysqli_connect() function to
open a new connection to the MySQL server.
mysqli_connect(host,username,password,dbname);
MySQL Connect
<?php
$connection = mysqli_connect("localhost","root","","awd_db");
// Check connection
if (mysqli_connect_errno($connection))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($connection);
Comments
# this is a comment
-- This is also a comment
/*
This
is a
comment
*/
SELECT * FROM cms_news;
Whitespace and Semi-colons
DEMO
Case Sensitivity
• Although database, table, and trigger names
are not case sensitive on some platforms, you
should not refer to one of these using
different cases within the same statement.
SELECT * FROM my_table WHERE MY_TABLE.col=1;
Case Sensitivity
• Column, index, stored routine, and event
names are not case sensitive on any platform,
nor are column aliases.
• By default, table aliases are case sensitive on
Unix, but not so on Windows or Mac OS X. The
following statement would not work on Unix,
because it refers to the alias both as a and as
A:
SELECT col_name FROM tbl_name AS a WHERE
a.col_name = 1 OR A.col_name = 2;
SELECTing All Columns in All Rows
• SELECT Syntax
SELECT expressions_and_columns FROM table_name
[WHERE some_condition_is_true]
[ORDER BY some_column [ASC | DESC]]
[LIMIT offset, rows]
SELECT * FROM tbl_name;
SELECTing Specific Columns
• If you do not want to see entire rows from
your table, just name the columns in which
you are interested, separated by commas.
SELECT name_id, firstname, lastname FROM
tbl_name;
Sorting Records
• By default, results of SELECT queries are
ordered as they appear in the table. If you
want to order results a specific way, such as by
date, ID, name, and so on, specify your
requirements using the ORDER BY clause.
SELECT name_id, firstname, lastname FROM
tbl_name ORDER BY lastname;
Sorting By a Single Column
• The default sorting of ORDER BY results is
ascending (ASC); strings sort from A to Z,
integers start at 0, dates sort from oldest to
newest. You can also specify a descending
sort, using DESC.
SELECT name_id, firstname, lastname FROM
tbl_name ORDER BY lastname DESC;
Sorting By Multiple Columns
• You're not limited to sorting by just one
field—you can specify as many fields as you
want, separated by commas. The sorting
priority is by list order, so if you use ORDER BY
lastname, firstname, the results will be sorted
by lastname, then by firstname.
SELECT name_id, firstname, lastname FROM
tbl_name ORDER BY lastname, firstname;
Sorting by Column Position
• Columns selected for output can be referred
to in ORDER BY and GROUP BY clauses using
column names, column aliases, or column
positions. Column positions are integers and
begin with 1
SELECT name_id, firstname, lastname FROM
tbl_name ORDER BY 2;
The WHERE Clause and Operator
Symbols
• We can use a conditional clause called WHERE clause
to filter out results. Using WHERE clause we can
specify a selection criteria to select required records
from a table.
• You can use one or more tables separated by comma
to include various condition using a WHERE clause. But
WHERE clause is an optional part of SELECT command.
• You can specify any condition using WHERE clause.
• You can specify more than one conditions using AND or
OR operators.
• A WHERE clause can be used along with DELETE or
UPDATE SQL command also to specify a condition.
The WHERE Clause and Operator
Symbols
The WHERE Clause and Operator
Symbols
SELECT * FROM cms_news WHERE `id` != 1;
SELECT * FROM cms_news WHERE `id` >= 1;
Checking for Equality
DEMO
Checking for Inequality
DEMO
Checking for Greater or Less Than
DEMO
Checking for NULL
• IS NULL: operator returns true of column value
is NULL.
• IS NOT NULL: operator returns true of column
value is not NULL.
SELECT * FROM cms_news WHERE title IS NULL;
SELECT * FROM cms_news WHERE title IS NOT
NULL;
The WHERE Clause and Operator
Words
SELECT * FROM cms_news WHERE `id` = 1 OR `id` = 2;
SELECT * FROM cms_news WHERE `id` = 1 AND
`status` = "a”;
The BETWEEN Operator
• The BETWEEN operator allows you to specify a
range to test.
SELECT productCode,
productName,
buyPrice
FROM products
WHERE buyPrice BETWEEN 90 AND 100
The IN Operator
• The IN operator allows you to determine if a
specified value matches any one of a list or a
subquery.
SELECT column_list
FROM table_name
WHERE (expr|column) IN
('value1','value2',...)
SELECT officeCode, city, phone
FROM offices
WHERE country IN ('USA','France')
The LIKE Operator
• The MySQL LIKE operator is commonly used to
select data based on patterns matching. Using
the LIKE operator in appropriate way is
essential to increase the query performance.
– The percentage ( %) wildcard allows you to match
any string of zero or more characters.
– The underscore (_) wildcard allows you to match
any single character.
The LIKE Operator
SELECT employeeNumber, lastName, firstName
FROM employees
WHERE firstName LIKE 'a%'
SELECT employeeNumber, lastName, firstName
FROM employees
WHERE lastname LIKE '%on%'
SELECT employeeNumber, lastName, firstName
FROM employees
WHERE firstname LIKE 'T_m'
DEMO
QUESTIONS?

Más contenido relacionado

La actualidad más candente

SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6Umair Amjad
 
SQA server performance tuning
SQA server performance tuningSQA server performance tuning
SQA server performance tuningDuy Tan Geek
 
XML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronXML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronEmiel Paasschens
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesIsaac Mosquera
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Goldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesGoldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesDave Stokes
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningOSSCube
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objectsSyed Zaid Irshad
 
Episode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceEpisode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceJitendra Zaa
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle databaseSalman Memon
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesSmitha Padmanabhan
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBOvais Tariq
 
SQL Pass Through and the ODBC Interface
SQL Pass Through and the ODBC InterfaceSQL Pass Through and the ODBC Interface
SQL Pass Through and the ODBC Interfacejrhampt
 
Sql Pass Through
Sql Pass ThroughSql Pass Through
Sql Pass Throughjrhampt
 

La actualidad más candente (20)

SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6SQL WORKSHOP::Lecture 6
SQL WORKSHOP::Lecture 6
 
SQA server performance tuning
SQA server performance tuningSQA server performance tuning
SQA server performance tuning
 
XML Business Rules Validation with Schematron
XML Business Rules Validation with SchematronXML Business Rules Validation with Schematron
XML Business Rules Validation with Schematron
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Goldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL QueriesGoldilocks and the Three MySQL Queries
Goldilocks and the Three MySQL Queries
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Indexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuningIndexing the MySQL Index: Key to performance tuning
Indexing the MySQL Index: Key to performance tuning
 
Creating other schema objects
Creating other schema objectsCreating other schema objects
Creating other schema objects
 
Episode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceEpisode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in Salesforce
 
Creating Views - oracle database
Creating Views - oracle databaseCreating Views - oracle database
Creating Views - oracle database
 
Oracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practicesOracle SQL, PL/SQL best practices
Oracle SQL, PL/SQL best practices
 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
SQL Pass Through and the ODBC Interface
SQL Pass Through and the ODBC InterfaceSQL Pass Through and the ODBC Interface
SQL Pass Through and the ODBC Interface
 
Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 
Sql views
Sql viewsSql views
Sql views
 
Sql Pass Through
Sql Pass ThroughSql Pass Through
Sql Pass Through
 

Destacado

Chapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemChapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemEddyzulham Mahluzydde
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationGuru Ji
 
Database Management Systems (DBMS)
Database Management Systems (DBMS)Database Management Systems (DBMS)
Database Management Systems (DBMS)Dimara Hakim
 
Database management system
Database management systemDatabase management system
Database management systemRizwanHafeez
 

Destacado (9)

DBMS basics
DBMS basicsDBMS basics
DBMS basics
 
DBMS an Example
DBMS an ExampleDBMS an Example
DBMS an Example
 
Chapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management SystemChapter 1 Fundamentals of Database Management System
Chapter 1 Fundamentals of Database Management System
 
CBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL PresentationCBSE XII Database Concepts And MySQL Presentation
CBSE XII Database Concepts And MySQL Presentation
 
Database Management Systems (DBMS)
Database Management Systems (DBMS)Database Management Systems (DBMS)
Database Management Systems (DBMS)
 
Database management system
Database management systemDatabase management system
Database management system
 
Data Base Management System
Data Base Management SystemData Base Management System
Data Base Management System
 
Basic DBMS ppt
Basic DBMS pptBasic DBMS ppt
Basic DBMS ppt
 
Dbms slides
Dbms slidesDbms slides
Dbms slides
 

Similar a MySQL basics

SQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfSQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfMadhusha15
 
Sql server 2016 queries
Sql server 2016 queriesSql server 2016 queries
Sql server 2016 queriesSeyed Ibrahim
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesAshwin Dinoriya
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfTamiratDejene1
 
FOUNDATION OF DATA SCIENCE SQL QUESTIONS
FOUNDATION OF DATA SCIENCE SQL QUESTIONSFOUNDATION OF DATA SCIENCE SQL QUESTIONS
FOUNDATION OF DATA SCIENCE SQL QUESTIONSHITIKAJAIN4
 
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 knowPavithSingh
 
Fortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuFortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuMarco Tusa
 
Optimizer overviewoow2014
Optimizer overviewoow2014Optimizer overviewoow2014
Optimizer overviewoow2014Mysql User Camp
 
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best PracticesAmazon Web Services
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxYashaswiniSrinivasan1
 

Similar a MySQL basics (20)

SQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdfSQL Lesson 6 - Select.pdf
SQL Lesson 6 - Select.pdf
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
SQL LECTURE.pptx
SQL LECTURE.pptxSQL LECTURE.pptx
SQL LECTURE.pptx
 
Sql server 2016 queries
Sql server 2016 queriesSql server 2016 queries
Sql server 2016 queries
 
Subqueries, Backups, Users and Privileges
Subqueries, Backups, Users and PrivilegesSubqueries, Backups, Users and Privileges
Subqueries, Backups, Users and Privileges
 
Practical 03 (1).pptx
Practical 03 (1).pptxPractical 03 (1).pptx
Practical 03 (1).pptx
 
IR SQLite Session #1
IR SQLite Session #1IR SQLite Session #1
IR SQLite Session #1
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
FOUNDATION OF DATA SCIENCE SQL QUESTIONS
FOUNDATION OF DATA SCIENCE SQL QUESTIONSFOUNDATION OF DATA SCIENCE SQL QUESTIONS
FOUNDATION OF DATA SCIENCE SQL QUESTIONS
 
DB2 Sql Query
DB2 Sql QueryDB2 Sql Query
DB2 Sql Query
 
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
 
Fortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleuFortify aws aurora_proxy_2019_pleu
Fortify aws aurora_proxy_2019_pleu
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
Optimizer overviewoow2014
Optimizer overviewoow2014Optimizer overviewoow2014
Optimizer overviewoow2014
 
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
(BDT401) Amazon Redshift Deep Dive: Tuning and Best Practices
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Day 6.pptx
Day 6.pptxDay 6.pptx
Day 6.pptx
 
MySQL for beginners
MySQL for beginnersMySQL for beginners
MySQL for beginners
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data   SQL Inteoduction to SQL manipulating of data
SQL Inteoduction to SQL manipulating of data
 

Más de Jamshid Hashimi

Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Jamshid Hashimi
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Jamshid Hashimi
 
Introduction to C# - Week 0
Introduction to C# - Week 0Introduction to C# - Week 0
Introduction to C# - Week 0Jamshid Hashimi
 
RIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyRIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyJamshid Hashimi
 
How Coding Can Make Your Life Better
How Coding Can Make Your Life BetterHow Coding Can Make Your Life Better
How Coding Can Make Your Life BetterJamshid Hashimi
 
Tips for Writing Better Code
Tips for Writing Better CodeTips for Writing Better Code
Tips for Writing Better CodeJamshid Hashimi
 
Launch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationLaunch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationJamshid Hashimi
 
Introduction to Blogging
Introduction to BloggingIntroduction to Blogging
Introduction to BloggingJamshid Hashimi
 
Introduction to Wordpress
Introduction to WordpressIntroduction to Wordpress
Introduction to WordpressJamshid Hashimi
 
CodeIgniter Helper Functions
CodeIgniter Helper FunctionsCodeIgniter Helper Functions
CodeIgniter Helper FunctionsJamshid Hashimi
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class ReferenceJamshid Hashimi
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniterJamshid Hashimi
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterJamshid Hashimi
 

Más de Jamshid Hashimi (20)

Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2
 
Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1Week 1: Getting Your Hands Dirty - Part 1
Week 1: Getting Your Hands Dirty - Part 1
 
Introduction to C# - Week 0
Introduction to C# - Week 0Introduction to C# - Week 0
Introduction to C# - Week 0
 
RIST - Research Institute for Science and Technology
RIST - Research Institute for Science and TechnologyRIST - Research Institute for Science and Technology
RIST - Research Institute for Science and Technology
 
How Coding Can Make Your Life Better
How Coding Can Make Your Life BetterHow Coding Can Make Your Life Better
How Coding Can Make Your Life Better
 
Mobile Vision
Mobile VisionMobile Vision
Mobile Vision
 
Tips for Writing Better Code
Tips for Writing Better CodeTips for Writing Better Code
Tips for Writing Better Code
 
Launch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media IntegrationLaunch Your Local Blog & Social Media Integration
Launch Your Local Blog & Social Media Integration
 
Customizing Your Blog 2
Customizing Your Blog 2Customizing Your Blog 2
Customizing Your Blog 2
 
Customizing Your Blog 1
Customizing Your Blog 1Customizing Your Blog 1
Customizing Your Blog 1
 
Introduction to Blogging
Introduction to BloggingIntroduction to Blogging
Introduction to Blogging
 
Introduction to Wordpress
Introduction to WordpressIntroduction to Wordpress
Introduction to Wordpress
 
CodeIgniter Helper Functions
CodeIgniter Helper FunctionsCodeIgniter Helper Functions
CodeIgniter Helper Functions
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class Reference
 
Managing Applications in CodeIgniter
Managing Applications in CodeIgniterManaging Applications in CodeIgniter
Managing Applications in CodeIgniter
 
CodeIgniter Practice
CodeIgniter PracticeCodeIgniter Practice
CodeIgniter Practice
 
CodeIgniter & MVC
CodeIgniter & MVCCodeIgniter & MVC
CodeIgniter & MVC
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
 
Exception & Database
Exception & DatabaseException & Database
Exception & Database
 
MySQL Record Operations
MySQL Record OperationsMySQL Record Operations
MySQL Record Operations
 

Último

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 

Último (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 

MySQL basics

  • 1. MySQL Basics Jamshid Hashimi Trainer, Cresco Solution http://www.jamshidhashimi.com jamshid@netlinks.af @jamshidhashimi ajamshidhashimi Afghanistan Workforce Development Program
  • 2. Agenda • Introduction MySQL • Simple Select • MySQL Connect • Comments • Whitespace and Semi-colons • Case Sensitivity • SELECTing All Columns in All Rows • SELECTing Specific Columns • Sorting Records • Sorting By a Single Column • Sorting By Multiple Columns • Sorting By Column Position
  • 3. Agenda • Ascending and Descending Sorts • The WHERE Clause and Operator Symbols • Checking for Equality • Checking for Inequality • Checking for Greater or Less Than • Checking for NULL • The WHERE Clause and Operator Words • The BETWEEN Operator • The IN Operator • The LIKE Operator • The NOT Operator • Checking Multiple Conditions • AND, OR, Order of Evaluation
  • 4. Introduction MySQL • MySQL is a fast, easy-to-use RDBMS used being used for many small and big businesses. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation. MySQL is becoming so popular because of many good reasons. • MySQL is released under an open-source license. So you have nothing to pay to use it. • MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most expensive and powerful database packages. • MySQL uses a standard form of the well-known SQL data language. • MySQL works on many operating systems and with many languages including PHP, PERL, C, C++, JAVA etc.
  • 5. Introduction to MySQL • MySQL works very quickly and works well even with large data sets. • MySQL is very friendly to PHP, the most appreciated language for web development. • MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million terabytes (TB). • MySQL is customizable. The open source GPL license allows programmers to modify the MySQL software to fit their own specific environments.
  • 6. Simple SELECT • A query is a question or a request SELECT last_name FROM employees
  • 7. MySQL Connect • Use the PHP mysqli_connect() function to open a new connection to the MySQL server. mysqli_connect(host,username,password,dbname);
  • 8. MySQL Connect <?php $connection = mysqli_connect("localhost","root","","awd_db"); // Check connection if (mysqli_connect_errno($connection)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_close($connection);
  • 9. Comments # this is a comment -- This is also a comment /* This is a comment */ SELECT * FROM cms_news;
  • 11. Case Sensitivity • Although database, table, and trigger names are not case sensitive on some platforms, you should not refer to one of these using different cases within the same statement. SELECT * FROM my_table WHERE MY_TABLE.col=1;
  • 12. Case Sensitivity • Column, index, stored routine, and event names are not case sensitive on any platform, nor are column aliases. • By default, table aliases are case sensitive on Unix, but not so on Windows or Mac OS X. The following statement would not work on Unix, because it refers to the alias both as a and as A: SELECT col_name FROM tbl_name AS a WHERE a.col_name = 1 OR A.col_name = 2;
  • 13. SELECTing All Columns in All Rows • SELECT Syntax SELECT expressions_and_columns FROM table_name [WHERE some_condition_is_true] [ORDER BY some_column [ASC | DESC]] [LIMIT offset, rows] SELECT * FROM tbl_name;
  • 14. SELECTing Specific Columns • If you do not want to see entire rows from your table, just name the columns in which you are interested, separated by commas. SELECT name_id, firstname, lastname FROM tbl_name;
  • 15. Sorting Records • By default, results of SELECT queries are ordered as they appear in the table. If you want to order results a specific way, such as by date, ID, name, and so on, specify your requirements using the ORDER BY clause. SELECT name_id, firstname, lastname FROM tbl_name ORDER BY lastname;
  • 16. Sorting By a Single Column • The default sorting of ORDER BY results is ascending (ASC); strings sort from A to Z, integers start at 0, dates sort from oldest to newest. You can also specify a descending sort, using DESC. SELECT name_id, firstname, lastname FROM tbl_name ORDER BY lastname DESC;
  • 17. Sorting By Multiple Columns • You're not limited to sorting by just one field—you can specify as many fields as you want, separated by commas. The sorting priority is by list order, so if you use ORDER BY lastname, firstname, the results will be sorted by lastname, then by firstname. SELECT name_id, firstname, lastname FROM tbl_name ORDER BY lastname, firstname;
  • 18. Sorting by Column Position • Columns selected for output can be referred to in ORDER BY and GROUP BY clauses using column names, column aliases, or column positions. Column positions are integers and begin with 1 SELECT name_id, firstname, lastname FROM tbl_name ORDER BY 2;
  • 19. The WHERE Clause and Operator Symbols • We can use a conditional clause called WHERE clause to filter out results. Using WHERE clause we can specify a selection criteria to select required records from a table. • You can use one or more tables separated by comma to include various condition using a WHERE clause. But WHERE clause is an optional part of SELECT command. • You can specify any condition using WHERE clause. • You can specify more than one conditions using AND or OR operators. • A WHERE clause can be used along with DELETE or UPDATE SQL command also to specify a condition.
  • 20. The WHERE Clause and Operator Symbols
  • 21. The WHERE Clause and Operator Symbols SELECT * FROM cms_news WHERE `id` != 1; SELECT * FROM cms_news WHERE `id` >= 1;
  • 24. Checking for Greater or Less Than DEMO
  • 25. Checking for NULL • IS NULL: operator returns true of column value is NULL. • IS NOT NULL: operator returns true of column value is not NULL. SELECT * FROM cms_news WHERE title IS NULL; SELECT * FROM cms_news WHERE title IS NOT NULL;
  • 26. The WHERE Clause and Operator Words SELECT * FROM cms_news WHERE `id` = 1 OR `id` = 2; SELECT * FROM cms_news WHERE `id` = 1 AND `status` = "a”;
  • 27. The BETWEEN Operator • The BETWEEN operator allows you to specify a range to test. SELECT productCode, productName, buyPrice FROM products WHERE buyPrice BETWEEN 90 AND 100
  • 28. The IN Operator • The IN operator allows you to determine if a specified value matches any one of a list or a subquery. SELECT column_list FROM table_name WHERE (expr|column) IN ('value1','value2',...) SELECT officeCode, city, phone FROM offices WHERE country IN ('USA','France')
  • 29. The LIKE Operator • The MySQL LIKE operator is commonly used to select data based on patterns matching. Using the LIKE operator in appropriate way is essential to increase the query performance. – The percentage ( %) wildcard allows you to match any string of zero or more characters. – The underscore (_) wildcard allows you to match any single character.
  • 30. The LIKE Operator SELECT employeeNumber, lastName, firstName FROM employees WHERE firstName LIKE 'a%' SELECT employeeNumber, lastName, firstName FROM employees WHERE lastname LIKE '%on%' SELECT employeeNumber, lastName, firstName FROM employees WHERE firstname LIKE 'T_m'
  • 31. DEMO