tMySQL Tutorial
tMySQL Tutorial
MySQL Tutorial
scalable, and easy to use
MySQL is cross-platform
MySQL is a widely used relational MySQL is compliant with the
database management system ANSI SQL standard
(RDBMS). MySQL was first released in
1995
MySQL is free and open-source. MySQL is developed,
distributed, and supported by
MySQL is ideal for both small and Oracle Corporation
large applications. MySQL is named after co-
founder Monty Widenius's
Examples in Each daughter: My
1
RDBMS stands for Relational
Database Management System.
What is a Database
Table?
RDBMS is a program used to
maintain a relational database. A table is a collection of related
data entries, and it consists of
RDBMS is the basis for all modern columns and rows.
database systems such as MySQL,
Microsoft SQL Server, Oracle, and A column holds specific information
Microsoft Access. about every record in the table.
RDBMS uses SQL queries to access A record (or row) is each individual
the data in the database. entry that exists in a table.
Customers Table
CustomerI CustomerName ContactNam Address City PostalCo Countr
2
D e de y
German
1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209
y
Ana Trujillo Avda. de la
México
2 Emparedados y Ana Trujillo Constitución 05021 Mexico
D.F.
helados 2222
Antonio Moreno Antonio México
3 Mataderos 2312 05023 Mexico
Taquería Moreno D.F.
Thomas
4 Around the Horn 120 Hanover Sq. London WA1 1DP UK
Hardy
Christina
5 Berglunds snabbköp Berguvsvägen 8 Luleå S-958 22 Sweden
Berglund
3
Package 3199
Federal (503) 555-
3
Shipping 9931
4
The MySQL SELECT Here, column1, column2, ... are the
field names of the table you want
Statement to select data from. If you want to
select all the fields available in the
The SELECT statement is used to table, use the following syntax:
select data from a database.
SELECT * FROM table_name;
The data returned is stored in a
result table, called the result-set. Demo Database
In this tutorial we will use the well-
SELECT Syntax known Northwind sample database.
SELECT column1, column2, ...
FROM table_name; Below is a selection from the
"Customers" table in the Northwind
sample database:
Custo
CustomerNam PostalCod
merI ContactName Address City Country
e e
D
Alfreds
1 Maria Anders Obere Str. 57 Berlin 12209 Germany
Futterkiste
Ana Trujillo
Avda. de la México
2 Emparedados y Ana Trujillo 05021 Mexico
Constitución 2222 D.F.
helados
Antonio Moreno México
3 Antonio Moreno Mataderos 2312 05023 Mexico
Taquería D.F.
4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK
Berglunds Christina
5 Berguvsvägen 8 Luleå S-958 22 Sweden
snabbköp Berglund
5
Inside a table, a column often The following SQL statement
contains many duplicate values; counts and returns the number of
and sometimes you only want to different (distinct) countries in the
list the different (distinct) values. "Customers" table:
The following SQL statement Note: The WHERE clause is not only
selects only the DISTINCT values used in SELECT statements, it is also
from the "Country" column in the used in UPDATE, DELETE, etc.!
"Customers" table:
Example
Demo Database
SELECT DISTINCT Country FROM
Below is a selection from the
Customers;
"Customers" table in the Northwind
sample database:
6
Emparedados y Constitución
D.F.
helados 2222
Antonio Moreno Antonio Mataderos México
3 05023 Mexico
Taquería Moreno 2312 D.F.
Thomas 120 Hanover Londo
4 Around the Horn WA1 1DP UK
Hardy Sq. n
Berglunds Christina Berguvsväge
5 Luleå S-958 22 Sweden
snabbköp Berglund n8