SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
SQL – A Tutorial
Part I
Gagan Deep
Director, Rozy Computech Services
3rd Gate, Kurukshetra University
Kurukshetra-136119
rozygag@yahoo.com
STRUCTURED QUERY LANGUAGE

• SQL, a Structured Query Language is now available
with most RDBMS (Relational Database
Management System) products as the database
language (which can be used both by end-users
and system programmers). Originally, SQL was
called SEQUEL( for Structured English QUEry
Language). SQL is now standard language for
commercial relational DBMS.
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
• First reason, a query in relational algebra is
written as a sequence of operations that, after
execution, produce the required result. Hence,
the user must specify how –that is, in what
order – to execute the query operations.
• On the other hand, the SQL provides a highlevel declarative language interface, so the user
only specifies what the result is to be, leaving
the actual optimization and decision on how to
execute the query to the DBMS.

Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
CHARACTERISTICS OF SQL
• User Friendly. The SQL syntax is more userfriendly than other formal languages.
• Comprehensive database language. SQL is a
comprehensive database language (DDL, DML &
DCL);
it
has
statements
for
data
definition, query, and update. Also have a facility
for defining views on the database, for specifying
security and authorization, for defining integrity
constraints, and for specifying transaction
controls.
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
• Easy to learn. The language while being simple
and easy to learn can cope with complex
situations.
• SQL Applications can be easily ported across
other systems. Such porting could be required
when the underlying DBMS (Data Base
Management System) needs to be upgraded
because of change in transaction volumes or
when a system developed in one environment is
to be used on another DBMS.
• The results to be expected are well defined.
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
• Allow end-users and systems personnel to deal
with a number of database management
systems where it is available.
• Independent Implementation : As a language its
implementation is independent. A query return
the same result regardless of whether
optimizing has been done with indexes or not.
• Embedded DML. It also has a rules for
embedding SQL statements into a generalpurpose programming language such as Fortran,
Cobol, C and Pascal.
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
• Allow end-users and systems personnel to deal
with a number of database management systems
where it is available.
• Independent Implementation : As a language its
implementation is independent. A query return
the same result regardless of whether optimizing
has been done with indexes or not.
• Embedded DML. It also has a rules for
embedding SQL statements into a generalpurpose programming language such as
Fortran, Cobol, C and Pascal.
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
ELEMENTS/COMPONENTS OF SQL
There are three components of SQL
• Data Definition Language(DDL)
• Data Manipulation Language(DML)
• Data Control Language(DCL)
DATA DEFINITION IN SQL
Data Definition Language, which is used for
specifying the database schema-to create, modify
and destroy tables, views and indexes.
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
Creating & Deleting Database
• First necessity to startup with SQL database is to
create database
• Creating a database
mysql> CREATE database student;
Query OK, 1 row affected (0.00 sec)
• Deleting a database
mysql> DROP database student;
Query OK, 0 rows affected (0.00 sec)
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
Creating a table
• After we have created the database we use the USE
statement to change the current database;
mysql> USE student;
Database changed
• Creating a table in the database is achieved with the
CREATE table statement
mysql> CREATE TABLE stud (
-> last_name varchar(15) not null,
-> first_name varchar(15) not null,
-> class varchar(8) not null,
-> city varchar(20) not null,
-> birth date not null default '0000-00-00',
-> );
Query OK, 0 rows affected (0.00 sec)
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
Examining the Result
•

To see what tables are present in the database use the SHOW tables:
mysql> SHOW tables;
+---------------------------+
| Tables_in_student |
+----------------------------+
| stud
|
+----------------------------+
1 row in set (0.00 sec)

•

The command DESCRIBE can be used to view the structure of a table
mysql> DESCRIBE stud;
+------------+-------------------+------------+-----------+------------+-------------+---------------------------------+
| Field
|
Type
| Null
| Key
| Default | Extra
| Privileges
|
+------------+-------------------+------------+-----------+------------+-------------+---------------------------------+
| last_name | varchar(15) |
|
|
|
| select,insert,update,references |
| first_name | varchar(15) |
|
|
|
| select,insert,update,references |
| class
| varchar(8) |
|
|
|
| select,insert,update,references |
| city
| varchar(20) |
|
|
|
| select,insert,update,references |
| birth
| date
|
|
| 0000-00-00 |
| select,insert,update,references |
+------------+-------------------+------------+-----------+------------+-------------+---------------------------------+
6 rows in set (0.00 sec)
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
Inserting / Retrieving Data into / from Tables
• To insert new rows into an existing table use the INSERT command:
mysql> INSERT INTO stud values (‘Sharma',
‘Rakesh',
‘BSc III',
‘Kurukshetra',
'19870212');
Query OK, 1 row affected (0.00 sec)
• With the SELECT command we can retrieve previously inserted rows:
mysql> SELECT * FROM stud;
+-------------+--------------+---------+---------------------+-----------+
|last_name |first_name | Class

| city

| birth

|

+-------------+--------------+---------+---------------------+------------+
| Sharma| Rakesh
| BSc III | Kurukshetra | 1987-02-12 |
+-------------+--------------+---------+---------------------+-----------+
1 row in set (0.00 sec)
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
Selecting Specific Rows and Columns
• Selecting rows by using the WHERE clause in the SELECT command
mysql> SELECT * FROM stud WHERE city=“Kurukshetra";
+-------------+--------------+---------+---------------------+-----------+
|last_name |first_name | Class

| city

| birth

|

+-------------+--------------+---------+---------------------+------------+
| Sharma| Rakesh
| BSc III | Kurukshetra | 1987-02-12 |
+-------------+--------------+---------+---------------------+-----------+
1 row in set (0.00 sec)
• Selecting specific columns by listing their names
mysql> SELECT class, first_name, last_name FROM stud;
+--------- +-------------+--------------+
| Class

|first_name | last_name |

+--------- +--------------+-------------+
| BSc III | Rakesh | Sharma |
+--------- +--------------+-------------+
1 row in set (0.00 sec)
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
Deleting and Updating Rows
• To modify or update entries in the table use the
UPDATE command
mysql> UPDATE student SET city=“Kaithal" WHERE
first_name=“Rakesh";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
• Deleting selected rows from a table using the DELETE
command
mysql> DELETE FROM stud WHERE
first_name=“Rakesh";
Query OK, 1 row affected (0.00 sec)
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
Loading a Database from a File
• Loading a your data from a file into a table.
• If we want to insert more records we have two
methods
1) with multiple INSERT commands : As we had
inserted one record in our last example
2) With Load data
• Assuming we have a file named “bsc3" in the current
directory, we can use the LOAD DATA command to
insert the data into the table stud.
mysql> LOAD DATA LOCAL INFILE ‘bsc3' INTO TABLE
stud;
Query OK, 45 rows affected (0.01 sec)
Records: 45 Deleted: 0 Skipped: 0 Warnings: 0
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
Exercise
• A general form of SELECT is:
SELECT what to select
FROM table(s)
WHERE condition that the data must satisfy;
• Comparison operators are:
< ; <= ; = ; != or <> ; >= ; >
• Logical operators are: AND ; OR ; NOT
• Comparison operator for special value NULL: IS
Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra University,
Kurukshetra, rozygag@yahoo.com
Exercises
1) mysql> SELECT * FROM stud WHERE city=“Kaithal";
2) mysql> SELECT last_name, first_name FROM stud
WHERE city=“Kaithal";
3) mysql> SELECT * FROM stud WHERE birth= NULL;
4) mysql> SELECT * FROM stud WHERE birth is NULL;
5) mysql> SELECT last_name, birth FROM stud WHERE
birth<"1987-01-01";
6) mysql> SELECT last_name, birth from stud ORDER BY
birth ASC LIMIT 1;
7) mysql> SELECT state, count(*) AS times FROM stud
GROUP BY city ORDER BY times DESC LIMIT 5;
8) mysql> SELECT * FROM stud WHERE(YEAR(now())YEAR(birth)) < 20;
• Useful function to retrieve parts of dates are: YEAR(),
Gagan Deep, Director, Rozy Computech
MONTH(), DAYOFMONTH(), TO_DAY().
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co
Thanks!

Gagan Deep, Director, Rozy Computech
Services, 3rd Gate, Kurukshetra
University, Kurukshetra, rozygag@yahoo.co

Más contenido relacionado

La actualidad más candente

Major features postgres 11
Major features postgres 11Major features postgres 11
Major features postgres 11EDB
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLMydbops
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance TuningMaven Logix
 
Sap basis administrator user guide
Sap basis administrator   user guideSap basis administrator   user guide
Sap basis administrator user guidePoguttuezhiniVP
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guidePoguttuezhiniVP
 
Postgresql Database Administration Basic - Day2
Postgresql  Database Administration Basic  - Day2Postgresql  Database Administration Basic  - Day2
Postgresql Database Administration Basic - Day2PoguttuezhiniVP
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3PoguttuezhiniVP
 
Row Level Security in databases advanced edition
Row Level Security in databases advanced editionRow Level Security in databases advanced edition
Row Level Security in databases advanced editionAlexander Tokarev
 
Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2rusersla
 
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops TeamEvolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops TeamMydbops
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Michael Renner
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQLNicole Ryan
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingAmir Reza Hashemi
 
9780538745840 ppt ch09
9780538745840 ppt ch099780538745840 ppt ch09
9780538745840 ppt ch09Terry Yoast
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 

La actualidad más candente (20)

Major features postgres 11
Major features postgres 11Major features postgres 11
Major features postgres 11
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
 
Introduction Mysql
Introduction Mysql Introduction Mysql
Introduction Mysql
 
PostGreSQL Performance Tuning
PostGreSQL Performance TuningPostGreSQL Performance Tuning
PostGreSQL Performance Tuning
 
Sap basis administrator user guide
Sap basis administrator   user guideSap basis administrator   user guide
Sap basis administrator user guide
 
Mysql database basic user guide
Mysql database basic user guideMysql database basic user guide
Mysql database basic user guide
 
Postgresql Database Administration Basic - Day2
Postgresql  Database Administration Basic  - Day2Postgresql  Database Administration Basic  - Day2
Postgresql Database Administration Basic - Day2
 
Postgresql Database Administration- Day3
Postgresql Database Administration- Day3Postgresql Database Administration- Day3
Postgresql Database Administration- Day3
 
Row Level Security in databases advanced edition
Row Level Security in databases advanced editionRow Level Security in databases advanced edition
Row Level Security in databases advanced edition
 
Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2Los Angeles R users group - Dec 14 2010 - Part 2
Los Angeles R users group - Dec 14 2010 - Part 2
 
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops TeamEvolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
Working with Databases and MySQL
Working with Databases and MySQLWorking with Databases and MySQL
Working with Databases and MySQL
 
Fudcon talk.ppt
Fudcon talk.pptFudcon talk.ppt
Fudcon talk.ppt
 
CQL3 in depth
CQL3 in depthCQL3 in depth
CQL3 in depth
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / Sharding
 
9780538745840 ppt ch09
9780538745840 ppt ch099780538745840 ppt ch09
9780538745840 ppt ch09
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 

Destacado

Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answersvijaybusu
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IVGagan Deep
 
Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning VGagan Deep
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning IIIGagan Deep
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- IGagan Deep
 
Software Engineering
Software Engineering Software Engineering
Software Engineering Gagan Deep
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural NetworksGagan Deep
 
Normalization 1
Normalization 1Normalization 1
Normalization 1Gagan Deep
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i iGagan Deep
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial IntelligenceGagan Deep
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statementsArun Nair
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MISGagan Deep
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2Gagan Deep
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLRam Kedem
 
Introduction to sql database on azure
Introduction to sql database on azureIntroduction to sql database on azure
Introduction to sql database on azureAntonios Chatzipavlis
 

Destacado (20)

Sql queries with answers
Sql queries with answersSql queries with answers
Sql queries with answers
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Software Project Planning IV
Software Project Planning IVSoftware Project Planning IV
Software Project Planning IV
 
Software Project Planning V
Software Project Planning VSoftware Project Planning V
Software Project Planning V
 
Software Project Planning III
Software Project Planning IIISoftware Project Planning III
Software Project Planning III
 
C – A Programming Language- I
C – A Programming Language- IC – A Programming Language- I
C – A Programming Language- I
 
Software Engineering
Software Engineering Software Engineering
Software Engineering
 
Fundamentals of Neural Networks
Fundamentals of Neural NetworksFundamentals of Neural Networks
Fundamentals of Neural Networks
 
Normalization 1
Normalization 1Normalization 1
Normalization 1
 
Normalization i i
Normalization   i iNormalization   i i
Normalization i i
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
retrieving data using SQL statements
retrieving data using SQL statementsretrieving data using SQL statements
retrieving data using SQL statements
 
Information System and MIS
Information System and MISInformation System and MIS
Information System and MIS
 
System Analysis & Design - 2
System Analysis & Design - 2System Analysis & Design - 2
System Analysis & Design - 2
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
SQL Server
SQL ServerSQL Server
SQL Server
 
Number system
Number systemNumber system
Number system
 
Introduction to sql database on azure
Introduction to sql database on azureIntroduction to sql database on azure
Introduction to sql database on azure
 
SQL | Computer Science
SQL | Computer ScienceSQL | Computer Science
SQL | Computer Science
 

Similar a SQL – A Tutorial I

Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracleyazidds2
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptxKulbir4
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019Dave Stokes
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Dinesh Neupane
 
MS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and MaintenanceMS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and MaintenanceVitaliy Fursov
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAiougVizagChapter
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQLSatoshi Nagayasu
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevMigration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevAltinity Ltd
 
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshootingTarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshootingJovan Popovic
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCOUM SAOKOSAL
 
Dimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQLDimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQLBrendan Furey
 
Test Data Transfer Tool
Test Data Transfer ToolTest Data Transfer Tool
Test Data Transfer ToolHai Nguyen
 

Similar a SQL – A Tutorial I (20)

Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
Jdbc oracle
Jdbc oracleJdbc oracle
Jdbc oracle
 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Oracle Material.pdf
Oracle Material.pdfOracle Material.pdf
Oracle Material.pdf
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
 
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
Connecting and using PostgreSQL database with psycopg2 [Python 2.7]
 
MS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and MaintenanceMS SQL Server 2008, Implementation and Maintenance
MS SQL Server 2008, Implementation and Maintenance
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
Aioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_featuresAioug vizag oracle12c_new_features
Aioug vizag oracle12c_new_features
 
10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL10 Reasons to Start Your Analytics Project with PostgreSQL
10 Reasons to Start Your Analytics Project with PostgreSQL
 
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander ZaitsevMigration to ClickHouse. Practical guide, by Alexander Zaitsev
Migration to ClickHouse. Practical guide, by Alexander Zaitsev
 
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshootingTarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
Tarabica 2019 (Belgrade, Serbia) - SQL Server performance troubleshooting
 
Java OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBCJava OOP Programming language (Part 8) - Java Database JDBC
Java OOP Programming language (Part 8) - Java Database JDBC
 
Dimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQLDimensional performance benchmarking of SQL
Dimensional performance benchmarking of SQL
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Database Management Homework Help
Database Management Homework Help Database Management Homework Help
Database Management Homework Help
 
Test Data Transfer Tool
Test Data Transfer ToolTest Data Transfer Tool
Test Data Transfer Tool
 

Más de Gagan Deep

Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning IIGagan Deep
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1Gagan Deep
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshareGagan Deep
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - IGagan Deep
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebraGagan Deep
 
Plsql overview
Plsql overviewPlsql overview
Plsql overviewGagan Deep
 

Más de Gagan Deep (7)

Software Project Planning II
Software Project Planning IISoftware Project Planning II
Software Project Planning II
 
Software Project Planning 1
Software Project Planning 1Software Project Planning 1
Software Project Planning 1
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
System Analysis & Design - I
System Analysis & Design - ISystem Analysis & Design - I
System Analysis & Design - I
 
Boolean algebra
Boolean algebraBoolean algebra
Boolean algebra
 
Plsql overview
Plsql overviewPlsql overview
Plsql overview
 

Último

What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?TechSoup
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationMJDuyan
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesMohammad Hassany
 
CAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxCAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxSaurabhParmar42
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsEugene Lysak
 
How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17Celine George
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17Celine George
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
Philosophy of Education and Educational Philosophy
Philosophy of Education  and Educational PhilosophyPhilosophy of Education  and Educational Philosophy
Philosophy of Education and Educational PhilosophyShuvankar Madhu
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxEduSkills OECD
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapitolTechU
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxMYDA ANGELICA SUAN
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 

Último (20)

What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?What is the Future of QuickBooks DeskTop?
What is the Future of QuickBooks DeskTop?
 
Benefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive EducationBenefits & Challenges of Inclusive Education
Benefits & Challenges of Inclusive Education
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming Classes
 
CAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptxCAULIFLOWER BREEDING 1 Parmar pptx
CAULIFLOWER BREEDING 1 Parmar pptx
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George Wells
 
How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17How to Use api.constrains ( ) in Odoo 17
How to Use api.constrains ( ) in Odoo 17
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17How to Add a many2many Relational Field in Odoo 17
How to Add a many2many Relational Field in Odoo 17
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
Philosophy of Education and Educational Philosophy
Philosophy of Education  and Educational PhilosophyPhilosophy of Education  and Educational Philosophy
Philosophy of Education and Educational Philosophy
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
 
CapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptxCapTechU Doctoral Presentation -March 2024 slides.pptx
CapTechU Doctoral Presentation -March 2024 slides.pptx
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 
Patterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptxPatterns of Written Texts Across Disciplines.pptx
Patterns of Written Texts Across Disciplines.pptx
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 

SQL – A Tutorial I

  • 1. SQL – A Tutorial Part I Gagan Deep Director, Rozy Computech Services 3rd Gate, Kurukshetra University Kurukshetra-136119 rozygag@yahoo.com
  • 2. STRUCTURED QUERY LANGUAGE • SQL, a Structured Query Language is now available with most RDBMS (Relational Database Management System) products as the database language (which can be used both by end-users and system programmers). Originally, SQL was called SEQUEL( for Structured English QUEry Language). SQL is now standard language for commercial relational DBMS. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 3. • First reason, a query in relational algebra is written as a sequence of operations that, after execution, produce the required result. Hence, the user must specify how –that is, in what order – to execute the query operations. • On the other hand, the SQL provides a highlevel declarative language interface, so the user only specifies what the result is to be, leaving the actual optimization and decision on how to execute the query to the DBMS. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 4. CHARACTERISTICS OF SQL • User Friendly. The SQL syntax is more userfriendly than other formal languages. • Comprehensive database language. SQL is a comprehensive database language (DDL, DML & DCL); it has statements for data definition, query, and update. Also have a facility for defining views on the database, for specifying security and authorization, for defining integrity constraints, and for specifying transaction controls. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 5. • Easy to learn. The language while being simple and easy to learn can cope with complex situations. • SQL Applications can be easily ported across other systems. Such porting could be required when the underlying DBMS (Data Base Management System) needs to be upgraded because of change in transaction volumes or when a system developed in one environment is to be used on another DBMS. • The results to be expected are well defined. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 6. • Allow end-users and systems personnel to deal with a number of database management systems where it is available. • Independent Implementation : As a language its implementation is independent. A query return the same result regardless of whether optimizing has been done with indexes or not. • Embedded DML. It also has a rules for embedding SQL statements into a generalpurpose programming language such as Fortran, Cobol, C and Pascal. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 7. • Allow end-users and systems personnel to deal with a number of database management systems where it is available. • Independent Implementation : As a language its implementation is independent. A query return the same result regardless of whether optimizing has been done with indexes or not. • Embedded DML. It also has a rules for embedding SQL statements into a generalpurpose programming language such as Fortran, Cobol, C and Pascal. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 8. ELEMENTS/COMPONENTS OF SQL There are three components of SQL • Data Definition Language(DDL) • Data Manipulation Language(DML) • Data Control Language(DCL) DATA DEFINITION IN SQL Data Definition Language, which is used for specifying the database schema-to create, modify and destroy tables, views and indexes. Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 9. Creating & Deleting Database • First necessity to startup with SQL database is to create database • Creating a database mysql> CREATE database student; Query OK, 1 row affected (0.00 sec) • Deleting a database mysql> DROP database student; Query OK, 0 rows affected (0.00 sec) Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 10. Creating a table • After we have created the database we use the USE statement to change the current database; mysql> USE student; Database changed • Creating a table in the database is achieved with the CREATE table statement mysql> CREATE TABLE stud ( -> last_name varchar(15) not null, -> first_name varchar(15) not null, -> class varchar(8) not null, -> city varchar(20) not null, -> birth date not null default '0000-00-00', -> ); Query OK, 0 rows affected (0.00 sec) Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 11. Examining the Result • To see what tables are present in the database use the SHOW tables: mysql> SHOW tables; +---------------------------+ | Tables_in_student | +----------------------------+ | stud | +----------------------------+ 1 row in set (0.00 sec) • The command DESCRIBE can be used to view the structure of a table mysql> DESCRIBE stud; +------------+-------------------+------------+-----------+------------+-------------+---------------------------------+ | Field | Type | Null | Key | Default | Extra | Privileges | +------------+-------------------+------------+-----------+------------+-------------+---------------------------------+ | last_name | varchar(15) | | | | | select,insert,update,references | | first_name | varchar(15) | | | | | select,insert,update,references | | class | varchar(8) | | | | | select,insert,update,references | | city | varchar(20) | | | | | select,insert,update,references | | birth | date | | | 0000-00-00 | | select,insert,update,references | +------------+-------------------+------------+-----------+------------+-------------+---------------------------------+ 6 rows in set (0.00 sec) Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 12. Inserting / Retrieving Data into / from Tables • To insert new rows into an existing table use the INSERT command: mysql> INSERT INTO stud values (‘Sharma', ‘Rakesh', ‘BSc III', ‘Kurukshetra', '19870212'); Query OK, 1 row affected (0.00 sec) • With the SELECT command we can retrieve previously inserted rows: mysql> SELECT * FROM stud; +-------------+--------------+---------+---------------------+-----------+ |last_name |first_name | Class | city | birth | +-------------+--------------+---------+---------------------+------------+ | Sharma| Rakesh | BSc III | Kurukshetra | 1987-02-12 | +-------------+--------------+---------+---------------------+-----------+ 1 row in set (0.00 sec) Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 13. Selecting Specific Rows and Columns • Selecting rows by using the WHERE clause in the SELECT command mysql> SELECT * FROM stud WHERE city=“Kurukshetra"; +-------------+--------------+---------+---------------------+-----------+ |last_name |first_name | Class | city | birth | +-------------+--------------+---------+---------------------+------------+ | Sharma| Rakesh | BSc III | Kurukshetra | 1987-02-12 | +-------------+--------------+---------+---------------------+-----------+ 1 row in set (0.00 sec) • Selecting specific columns by listing their names mysql> SELECT class, first_name, last_name FROM stud; +--------- +-------------+--------------+ | Class |first_name | last_name | +--------- +--------------+-------------+ | BSc III | Rakesh | Sharma | +--------- +--------------+-------------+ 1 row in set (0.00 sec) Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 14. Deleting and Updating Rows • To modify or update entries in the table use the UPDATE command mysql> UPDATE student SET city=“Kaithal" WHERE first_name=“Rakesh"; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 • Deleting selected rows from a table using the DELETE command mysql> DELETE FROM stud WHERE first_name=“Rakesh"; Query OK, 1 row affected (0.00 sec) Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 15. Loading a Database from a File • Loading a your data from a file into a table. • If we want to insert more records we have two methods 1) with multiple INSERT commands : As we had inserted one record in our last example 2) With Load data • Assuming we have a file named “bsc3" in the current directory, we can use the LOAD DATA command to insert the data into the table stud. mysql> LOAD DATA LOCAL INFILE ‘bsc3' INTO TABLE stud; Query OK, 45 rows affected (0.01 sec) Records: 45 Deleted: 0 Skipped: 0 Warnings: 0 Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 16. Exercise • A general form of SELECT is: SELECT what to select FROM table(s) WHERE condition that the data must satisfy; • Comparison operators are: < ; <= ; = ; != or <> ; >= ; > • Logical operators are: AND ; OR ; NOT • Comparison operator for special value NULL: IS Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.com
  • 17. Exercises 1) mysql> SELECT * FROM stud WHERE city=“Kaithal"; 2) mysql> SELECT last_name, first_name FROM stud WHERE city=“Kaithal"; 3) mysql> SELECT * FROM stud WHERE birth= NULL; 4) mysql> SELECT * FROM stud WHERE birth is NULL; 5) mysql> SELECT last_name, birth FROM stud WHERE birth<"1987-01-01"; 6) mysql> SELECT last_name, birth from stud ORDER BY birth ASC LIMIT 1; 7) mysql> SELECT state, count(*) AS times FROM stud GROUP BY city ORDER BY times DESC LIMIT 5; 8) mysql> SELECT * FROM stud WHERE(YEAR(now())YEAR(birth)) < 20; • Useful function to retrieve parts of dates are: YEAR(), Gagan Deep, Director, Rozy Computech MONTH(), DAYOFMONTH(), TO_DAY(). Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co
  • 18. Thanks! Gagan Deep, Director, Rozy Computech Services, 3rd Gate, Kurukshetra University, Kurukshetra, rozygag@yahoo.co