SQL Notes

SQL Notes

General Documentation

A Visual Explanation of SQL Joins
A Visual Explanation of SQL Joins (click for full size)

MySQL

Oracle

Explain Plans

To produce an Explain Plan:

explain plan set statement_id = '<SOME_IDENTIFIER>' for
/* ------ Your SQL here ------ */

To read an Explain Plan:

select operation, options, object_name
from plan_table
where statement_id = '<SOME_IDENTIFIER>'
start with id = 0
connect by prior id=parent_id and prior statement_id = statement_id;

Questions and Topics

Q. How can you find an orphan row in a join?

Do a Left Join (= Left Outer Join) and look for nulls.

select * 
from TABLE_A
  left outer join TABLE_B
    on TABLE_A.NAME = TABLE_B.NAME 
where TABLE_B.ID is null

sql_notes.txt · Last modified: 05/02/2013 19:35 by Daniel Kirkdorffer
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki