daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest May 16th, 2018 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ・表の結合の基本文法
  2. SELECT カラム名 表1 JOIN 表2 ON 結合条件 選択条件(WHERE, GROUP BY, HAVING) 表示条件(ORDER BY, LIMIT, OFFSET)
  3.  - 内部結合
  4.   結合条件を満たす行のみを選択
  5.  
  6.   + JOIN ON
  7. 例) SELECT e.emp_id, e.emp_name, d.dept_id, d.dept_name FROM employee e JOIN department d ON e.dept_id = d.dept_id;
  8. → 両表に含まれるdept_idを持つ行のみ表示される
  9.  
  10.   + USING
  11.    ON条件部分が同じ列名で等しい値を結合条件とする場合
  12. 例) SELECT emp_id, emp_name, d.dept_id, dept_name FROM employee e JOIN department d USING(dept_id);
  13. → 両表に同じ列名で含まれるdept_idにより結合
  14.  
  15.    + NATURAL JOIN
  16.    両表に同じ列名で含まれるカラム全てで結合する場合
  17. 例) SELECT emp_id, emp_name, d.dept_id, dept_name FROM employee e NATURAL JOIN department d;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top