Sql Bag 3 Join Tabel

  • Uploaded by: Euis Marlina
  • 0
  • 0
  • January 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sql Bag 3 Join Tabel as PDF for free.

More details

  • Words: 494
  • Pages: 15
Loading documents preview...
SQL (Structure Query Language) – MySQL (Bagian 3: Table Joins)

Oleh: Euis Marlina 08179424319 http://euismarlina.edublogs.org

Perintah SQL join tabel digunakan untuk

menampilkan data yang diambil dari beberapa tabel yang saling berhubungan. Kita dapat menampilkan beberapa kolom dari tabel 1, beberapa kolom dari tabel 2, dan beberapa kolom dari tabel n. Hampir semua perintah pada materi DML di bagian 2 dapat digabungkan penggunaannya dalam join table ini.

JOIN digunakan untuk menampilkan semua

record dari sebuah tabel yang cocok maupun tidak cocok dengan record dari tabel lainnya. JOIN digunakan ketika beberapa tabel diakses melalui sebuah statemen SQL yaitu SELECT. JOIN membandingkan semua kolom pada kedua tabel yang memiliki kesamaan nama kolom. Hasilnya adalah hanya menampilkan satu kolom untuk setiap pasang kolom yang namanya sama.

table_reference JOIN table_factor WHERE

| ON [join_condition] table_reference [INNER | CROSS] JOIN

table_factor WHERE [join_condition] table_reference STRAIGHT_JOIN

table_factor

table_reference STRAIGHT_JOIN

table_factor ON conditional_expr table_reference {LEFT|RIGHT} [OUTER]

JOIN table_reference ON join_condition table_reference NATURAL [{LEFT|

RIGHT} [OUTER]] JOIN table_factor WHERE join_condition

This type of join is the simplest join. The

cross join result in cartesian product of all the records from two tables. Jika pada tabel pertama ada 4 record, dan pada tabel kedua juga ada 4 record, maka jumlah record hasil query akan berjumlah 16 (hasil dari 4 x 4 =16) Syntax: table_reference CROSS JOIN table_factor | WHERE [join_condition]

This is the type of join where tables are

combined based on a common column. INNER JOIN memerlukan kriteria kolom tertentu sebagai penghubung kedua tabel. Syntax: table_reference INNER JOIN table_factor WHERE [join_condition] In MySQL, CROSS JOIN is a syntactic equivalent to INNER JOIN (they can replace each other).

Menampilkan record dari tabel sebelah kiri

yang cocok maupun yang tidak cocok dengan tabel sebelah kanan. Record yang tidak cocok, akan ditampilkan dengan nilai NULL. Syntax: table_reference LEFT [OUTER] JOIN table_reference ON join_condition

Menampilkan record yang cocok

dengan tabel sebelah kanan. Syntax: table_reference RIGHT [OUTER] JOIN table_reference ON join_condition

Table Joins Selain beberapa jenis join di atas, anda juga bisa menggunakan konsep join tabel yang sangat sederhana yaitu dengan cara: Jika ingin menampilkan semua field

SELECT * from table_1, table2; Jika ingin menampilkan field tertentu

SELECT table_1.field_1, table_2.field_2, table_2.field_3 from table_1, table2;

Contoh Contoh pada database mysql: SELECT * from help_relation, help_keyword; atau SELECT * from help_relation JOIN

help_keyword;

SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword,help_relation WHERE help_keyword.help_keyword_id=help_relatio n.help_keyword_id;

INNER/CROSS JOIN  SELECT * FROM help_keyword INNER JOIN

help_relation;

 SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword INNER JOIN help_relation WHERE help_keyword.help_keyword_id=help_relation.help_keyw ord_id;

 SELECT * FROM help_keyword CROSS JOIN

help_relation;

 SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword CROSS JOIN

STRAIGHT_JOIN SELECT * FROM help_keyword

STRAIGHT_JOIN help_relation; SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword STRAIGHT_JOIN help_relation ON help_keyword.help_keyword_id=help_relation. help_keyword_id;

LEFT/RIGHT [OUTER] JOIN SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword LEFT JOIN help_relation ON help_keyword.help_keyword_id=help_relation. help_keyword_id;

SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword RIGHT OUTER JOIN help_relation ON help_keyword.help_keyword_id=help_relation. help_keyword_id;

NATURAL LEFT/RIGHT [OUTER] JOIN SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword NATURAL RIGHT JOIN help_relation WHERE help_keyword.help_keyword_id=help_relation .help_keyword_id;

SELECT help_relation.help_keyword_id,

help_keyword.name from help_keyword NATURAL LEFT OUTER JOIN help_relation WHERE help_keyword.help_keyword_id=help_relation

Related Documents

Sql Bag 3 Join Tabel
January 2021 1
Td 3 Sql
February 2021 1
Sql
March 2021 0
Sql
January 2021 3
Makalah Sql
January 2021 1
Programacion Sql
March 2021 0

More Documents from "Harold Jose Arguello Morales"