do it with sql

18
DO IT WITH SQL PHP Indenesia Meetup 201404

Upload: nur-hidayat

Post on 09-May-2015

190 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Do IT with SQL

DO IT WITH SQLPHP Indenesia Meetup 201404

Page 2: Do IT with SQL

ABOUT ME

Editor PojokProgrammer.net Writers Welcome!

CEO BiruniLabs Trainers Welcome!

Page 3: Do IT with SQL

WHAT YOU NEED Laptop or Computer RDBMS Installed

MySQL PostgreSQL Oracle Whatever....

SQL Interface HeidiSQL SQLyog phpMyAdmin Whatever.....

Your Brain

Page 4: Do IT with SQL

BRAIN GYM

Page 5: Do IT with SQL

ARE YOU READY ?

Page 6: Do IT with SQL

HISTORY

IBM Research for System R SEQUEL Relational Software Inc. developed their

own version Oracle v2 (1979) IBM released DB2 based on System R

(1983) Becoming Standard

ANSI SQL-86 ANSI SQL-92

Page 7: Do IT with SQL

RULE OF THUMB

From Tom Kyte, Oracle Evangelist1. Use single SQL statement

whenever possible2. Use PL/SQL or Stored Procedure3. Use Java (or other programming

language)4. Rethink why you want to do it

(refine your approach)

Page 8: Do IT with SQL

SQL ANATOMY

Statements Queries Clauses Predicates Expressions

Page 9: Do IT with SQL

SELECTSELECT b,d,e,h

FROM some_table ;

SELECT *

FROM some_table

WHERE x IN (3,5,6,8) ;

SELECT b,d,e,h

FROM some_table

WHERE x IN (3,5,6,8) ;

Page 10: Do IT with SQL

JOIN VS UNION

JOIN UNION (UNION ALL)

Page 11: Do IT with SQL

JOIN

INNER JOIN (JOIN) LEFT OUTER JOIN (LEFT JOIN) RIGHT OUTER JOIN (RIGHT JOIN) FULL OUTER JOIN (FULL JOIN)  LEFT JOIN EXCLUDING INNER JOIN (LEFT

EXCLUDING JOIN) RIGHT JOIN EXCLUDING INNER JOIN (RIGHT

EXCLUDING JOIN) OUTER JOIN EXCLUDING INNER JOIN (OUTER

EXCLUDING JOIN)

Page 12: Do IT with SQL

VISUAL REPRESENTATION

Page 13: Do IT with SQL

SOME LOGIC

3VL (3 Value Logic) Conditional Expression

True False Null

CASE (ANSI) COALESCE (ANSI) DECODE (Oracle) IFNULL (MySQL) ISNULL (SQL Server)

Page 14: Do IT with SQL

AGGREGATES

SUM() COUNT() MAX() MIN() AVG() CROSS TABS

Page 15: Do IT with SQL

ANALYTIC FUNCTIONS

ROW_NUMBER() OVER() SUM() OVER() COUNT() OVER() MAX() OVER() MIN() OVER() AVG() OVER()

Page 16: Do IT with SQL

TRIGGERS & STORED PROCEDURES When to Use? How to Use?

Page 17: Do IT with SQL

TUNING

Optimizing Queries Optimizing Index Optimizing Server

Page 18: Do IT with SQL

THANK YOUQuestions and Answers