Learning MySQL! Angola Africa 1246700 20609294 100990000000. SELECT name, gdp/population FROM world WHERE area > 50000000!



Similar documents
SQL. Short introduction

P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur

A table is a collection of related data entries and it consists of columns and rows.

SQL INJECTION IN MYSQL

A basic create statement for a simple student table would look like the following.

SQL Basics for RPG Developers

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

Each Ad Hoc query is created by making requests of the data set, or View, using the following format.

Database: SQL, MySQL

Database Query 1: SQL Basics

SQL 2: GETTING INFORMATION INTO A DATABASE. MIS2502 Data Analytics

Concepts Design Basics Command-line MySQL Security Loophole

Using the SQL Procedure

Oracle SQL. Course Summary. Duration. Objectives

Unit 10: Microsoft Access Queries

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Oracle Database: SQL and PL/SQL Fundamentals

A Brief Introduction to MySQL

Oracle Database 10g Express

Serious Threat. Targets for Attack. Characterization of Attack. SQL Injection 4/9/2010 COMP On August 17, 2009, the United States Justice

Information Systems SQL. Nikolaj Popov

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Nebenfach)

Oracle Database 12c: Introduction to SQL Ed 1.1

David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation

Introducción a las bases de datos SQL Libro de referencia

Database Administration with MySQL

Deleting A Record Updating the Database Binding Data Tables to Controls Binding the Data Table to the Data Grid View...

Oracle Database: SQL and PL/SQL Fundamentals NEW

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

3.GETTING STARTED WITH ORACLE8i

Microsoft Access Lesson 5: Structured Query Language (SQL)

Darshan Institute of Engineering & Technology PL_SQL

Oracle Database: SQL and PL/SQL Fundamentals

Introduction to SQL and SQL in R. LISA Short Courses Xinran Hu

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

B.1 Database Design and Definition

Introduction to Database. Systems HANS- PETTER HALVORSEN,

Relational Databases. Christopher Simpkins

IBM DB Introduction to SQL and database objects Hands-on Lab. Information Management Cloud Computing Center of Competence.

Multimedia im Netz Online Multimedia Winter semester 2015/16

Introduction to Microsoft Jet SQL

Chapter 22 Database: SQL, MySQL,

Oracle Database: Introduction to SQL

Oracle Database 10g: Introduction to SQL

Oracle Database: Introduction to SQL

Teach Yourself InterBase

Chapter 1 Overview of the SQL Procedure

Oracle Database 11g SQL

SQL Server. 1. What is RDBMS?

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Lab 2: MS ACCESS Tables

Financial Data Access with SQL, Excel & VBA

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Advanced SQL. Jim Mason. Web solutions for iseries engineer, build, deploy, support, train

Oracle 10g PL/SQL Training

Knocker main application User manual

Lab 9 Access PreLab Copy the prelab folder, Lab09 PreLab9_Access_intro

Oracle For Beginners Page : 1

Oracle Database: Introduction to SQL

Microsoft Access 3: Understanding and Creating Queries

CS 2316 Data Manipulation for Engineers

Relational Database: Additional Operations on Relations; SQL

VBScript Database Tutorial Part 1

Advance DBMS. Structured Query Language (SQL)

Big Data Hive! Laurent d Orazio

Key Skills IT Level 3. Lagan Health Club. Classroom Activity

Microsoft Access Database Management through LabVIEW and MySQL

Chapter 5. Microsoft Access

How To Create A Table In Sql (Ahem)

Access Queries (Office 2003)

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Database Migration from MySQL to RDM Server

A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

T-SQL STANDARD ELEMENTS

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

MICROSOFT ACCESS 2003 TUTORIAL

Using AND in a Query: Step 1: Open Query Design

QW SQL Wizard (July 13, 2010)

The join operation allows you to combine related rows of data found in two tables into a single result set.

A Metadata-Driven Approach to Relational Database Management

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following:

VBA and Databases (see Chapter 14 )

Using SQL Queries in Crystal Reports

DIPLOMA IN WEBDEVELOPMENT

SQL Basics. Introduction to Standard Query Language

Unit 5.1 The Database Concept

Web Development using PHP (WD_PHP) Duration 1.5 months

Advanced Online Media Dr. Cindy Royal Texas State University - San Marcos School of Journalism and Mass Communication

DbSchema Tutorial with Introduction in SQL Databases

MS Access Lab 2. Topic: Tables

A brief MySQL tutorial. CSE 134A: Web Service Design and Programming Fall /28/2001

Web Programming Step by Step

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.

Creating QBE Queries in Microsoft SQL Server

Transcription:

Learning MySQL http://sqlzoo.net/wiki/select_basics Angola Africa 1246700 20609294 100990000000 1) Single quotes SELECT population FROM world WHERE name = Germany 2) Division SELECT name, gdp/population FROM world WHERE area > 50000000 3) AND 4) IN (check) SELECT name, continent FROM world WHERE area < 2000 AND gdp > 500000000 SELECT name, population FROM world WHERE name IN ( Finland, Norway, Denmark, Sweden ) 5) Wild cards and patten matching / LIKE SELECT name FROM world WHERE name LIKE G% 6) BETWEEN name continent area population gdp Afghanistan Asia 652230 25500100 20343000000 Albania Europe 28748 2831741 12960000000 Algeria Africa 2381741 37100000 188681000000 Andorra Europe 468 78115 3712000000 SELECT name, area/1000 FROM world WHERE area BETWEEN 203453 AND 53453 ------------------------------------------------------------------------------------------------------------------------ SQL is divided up into two parts: Data Manipulation Language (DML) and Data Definition Language (DLL). Query Commands: SELECT - extracts data from a database UPDATE - updates data in a database DELETE - deletes data from a database INSERT INTO - inserts new data into a database

DLL Commands CREATE DATABASE - creates new database ALTER DATABASE - modifies a database CREATE TABLE - creates a new table ALTER TABLE - modifies a table DROP TABLE - deletes a table CREATE INDEX - creates an index (search key) DROP INDEX - deletes an index SELECTING To SELECT from a table, you use the format SELECT lastname, firstname FROM persontable Using an * selects ALL. NAVIGATION Most database software allows you to navigate: Move-To-First-Record Get-Record-Content Move-To-Next-Record DISTINCT Used to select only the distinct (different) results. SELECT DISTINCT City FROM persons Returns: City Sandnes Stavanger

WHERE clause SELECT column_name(s) FROM table_name WHERE column_name operator value The WHERE clause is used to extract only those records that fulfill a specific criterion. SELECT * FROM Persons WHERE City= Sandnes Returns: Quotes around text fields SQL uses single quotes around text values. Numeric values should not be enclosed in quotes. SELECT * FROM Persons WHERE FirstName = Trove SELECT * FROM Persons WHERE Year =1995 Operators allowed in the WHERE clause = Equal < > Not equal (some versions it s =) > Greater than < Less than >= Greater than or equal <= Less than or equal BETWEEN - between an inclusive range LIKE - search for a pattern IN - to specify multiple possible values for a column

AND & OR operators The OR operator displays a record if either of the first or second conditions are true. The AND operator displays a record if both the first and the second conditions are true. - AND SELECT * FROM Persons WHERE FirstName= Trove AND Lastname= Svendson Result: - OR SELECT * FROM Persons WHERE FirstName= Trove OR FirstName= Ola Results: - AND & OR SELECT * FROM Persons WHERE LastName= Svendson AND (FirstName= Tove OR FirstName= Ola ) Result:

ORDER BY keyword The ORDER BY keyword is used to sort the result-set by a specified column. SELECT * FROM Persons ORDER BY LastName Result: (Ordered by last name characters) To ORDER BY DESC... descending order we do this: SELECT * FROM Persons ORDER BY LastName DESC Result: (Opposite to above) 4 Nilsen Tom Vingvn 23 Stavanger 4 Nilsen Tom Vingvn 23 Stavanger 4 Nilsen Tom Vingvn 23 Stavanger

INSERT INTO statement The INSERT INTO statement is used to insert a new row in a table. It is possible to write the INSERT INTO statement in two forms. The first form doesn t specify the column names where the data will be inserted, only their values. INSERT INTO table_name VALUES (value1, value2, value3,...) INSERT INTO table_name (column1, column2, column3,... ) VALUES (value1, value2, value3,... ) The second form specifies both the column names and the values to be inserted. INSERT INTO Persons VALUES (4, Nilsen, Johan, Bakken 2, Stavanger ) Result: 4 Nilsen Johan Bakken 2 Stavanger To insert data into specific columns: INSERT INTO Pearsons (P_Id, LastName, FirstName) VALUES (5, Tjessem, Jakob ) Result: 4 Nilsen Johan Bakken 2 Stavanger 5 Tjessem Jakob

SQL UPDATE statement The UPDATE statement is used to update existing records in a table. The WHERE clause MUST be present or all fields will be updated with the new info. UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value UPDATE Persons SET Address= Nissestien 67, City= Sandnes WHERE LastName= Tjessem AND FirstName= Jakob Result: 4 Nilsen Johan Bakken 2 Stavanger 5 Tjessem Jakob 4 Nilsen Johan Bakken 2 Stavanger 5 Tjessem Jakob Nissestien 67 Sandnes

The DELETE statement The DELETE statement is used to delete rows ina table. DELETE FROM table_name WHERE some_column=some_value