0% found this document useful (0 votes)
12 views2 pages

Latihan Outer Join Gumilang

The document details a series of commands executed in a MariaDB database environment, including the creation of a database and tables, as well as the insertion of records. It demonstrates SQL queries for joining tables and retrieving data, highlighting both successful and erroneous commands. Additionally, it showcases the use of foreign keys and the retrieval of items with and without sales records.

Uploaded by

Gumilang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Latihan Outer Join Gumilang

The document details a series of commands executed in a MariaDB database environment, including the creation of a database and tables, as well as the insertion of records. It demonstrates SQL queries for joining tables and retrieving data, highlighting both successful and erroneous commands. Additionally, it showcases the use of foreign keys and the retrieval of items with and without sales records.

Uploaded by

Gumilang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Microsoft Windows [Version 10.0.19045.

5608]
(c) Microsoft Corporation. All rights reserved.

C:\Users\thinkpad> cd c:\xampp\mysql\bin

c:\xampp\mysql\bin>mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.4.32-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database db_gilang;


Query OK, 1 row affected (0.025 sec)

MariaDB [(none)]> use db_gilang;


Database changed
MariaDB [db_gilang]> create table barang (
-> kode_barang varchar(10) primary key,
-> nama_barang varchar(15),
-> harga int(10),
-> stok int(10));
Query OK, 0 rows affected (0.032 sec)

MariaDB [db_gilang]> create table penjualan (


-> id_penjualan int(10) primary key,
-> kode_barang varchar(5),
-> jumlah int,
-> tanggal DATE,
-> FOREIGN KEY (kode_barang) REFERENCES barang (kode_barang)
-> );
Query OK, 0 rows affected (0.051 sec)

MariaDB [db_gilang]> insert into barang values


-> ('B001', 'Pensil', 2000, 80),
-> ('B002', 'Pulpen', 3000, 100),
-> ('B003', 'Buku Tulis', 5000, 60),
-> ('B004', 'Penghapus', 1500, 50);
Query OK, 4 rows affected (0.030 sec)
Records: 4 Duplicates: 0 Warnings: 0

MariaDB [db_gilang]> insert into penjualan values


-> (1, 'B001', 10, "2024-05-01"),
-> (2, 'B003', 5, "2024-05-01"),
-> (3, 'B004', 11, "2024-05-02");
Query OK, 3 rows affected (0.038 sec)
Records: 3 Duplicates: 0 Warnings: 0

MariaDB [db_gilang]> select barang.nama_barang, penjualan.jumlah from barang join


penjualan on barang.kode_barang = penjualan.kode_barang;
+-------------+--------+
| nama_barang | jumlah |
+-------------+--------+
| Pensil | 10 |
| Buku Tulis | 5 |
| Penghapus | 11 |
+-------------+--------+
3 rows in set (0.000 sec)

MariaDB [db_gilang]> select barang.nama_barang, penjualan.jumlah from barang left


join penjualan ON barang.kode_barang = penjualan.kode_barang;
+-------------+--------+
| nama_barang | jumlah |
+-------------+--------+
| Pensil | 10 |
| Buku Tulis | 5 |
| Penghapus | 11 |
| Pulpen | NULL |
+-------------+--------+
4 rows in set (0.001 sec)

MariaDB [db_gilang]>
MariaDB [db_gilang]> select nama_barang from barang left join penjualan ON
barang.kode_barang = penjuala.kode_barang where penjualan.kode_barang is null;
ERROR 1054 (42S22): Unknown column 'penjuala.kode_barang' in 'on clause'
MariaDB [db_gilang]> select nama_barang from barang left join penjualan ON
barang.kode_barang = penjualan.kode_barang where penjualan.kode_barang is null;
+-------------+
| nama_barang |
+-------------+
| Pulpen |
+-------------+
1 row in set (0.025 sec)

MariaDB [db_gilang]> select count (barang.kode_barang) from barang join penjualan


on barang.kode_barang = penjualan.kode_barang;
ERROR 1630 (42000): FUNCTION db_gilang.count does not exist. Check the 'Function
Name Parsing and Resolution' section in the Reference Manual
MariaDB [db_gilang]>

You might also like