Home > Database > SQL Join – Left Join

SQL Join – Left Join

September 3, 2013 Leave a comment Go to comments

Left Join keyword mengembalikan semua row pada table A ( table sebelum keyword LEFT JOIN ) yang cocok dengan row pada table B. Jika pasangannya tidak ditemukan, tabel B berisi NULL.

Syntax:

SELECT column_name(s) FROM tableA LEFT JOIN tableB ON tableA.column_name = tableB.column_name

Diagram venn Left join

Left Join

Left Join

Berikut ini contoh left join :

Table Customers :

Table Customers

Table Customers

Table Orders :

Table Orders

Table Orders

Left join statement:

SELECT customers.id, customers.name, customers.address, orders.oid, orders.customer_id, orders.amount from customers LEFT JOIN orders ON customers.id = orders.customer_id

Result :

Result

Semoga bermanfaat.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: