perintah sql dasar menggunakan union
yuli@yulychocho:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.6.30-0ubuntu0.14.04.1 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select nama from artis UNION select nama_artis from info_artis;
ERROR 1046 (3D000): No database selected
mysql> use yuliyanti;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select nama from artis UNION select nama_artis from info_artis;
+--------------------+
| nama |
+--------------------+
| DREW BARRYMORE |
| SHARON STONE |
| SYLVESTER STALLONE |
| KEVIN COSTER |
| JULLA ROBERT |
| DEMI MO0RE |
| CINDY CRAWFORD |
| CAMERON DLAZ |
| KEANU REEVES |
| SANDRA BULLOK |
| RICHARD GERE |
| DEMI MOORE |
| ANGELINA JOLIE |
| SANDRA BULLOCK |
| SYLVESTER STALLON |
+--------------------+
15 rows in set (0,03 sec)
mysql> create table air(
-> air varchar(20));
Query OK, 0 rows affected (0,68 sec)
mysql> insert into air values ("katak");
Query OK, 1 row affected (0,06 sec)
mysql> insert into air values ("ikan mas");
Query OK, 1 row affected (0,35 sec)
mysql> insert into air values ("ular");
Query OK, 1 row affected (0,06 sec)
mysql> insert into air values ("ikan hiu");
Query OK, 1 row affected (0,12 sec)
mysql> create table darat(darat varchar(20));
Query OK, 0 rows affected (2,04 sec)
mysql> insert into darat values ("katak");
Query OK, 1 row affected (0,07 sec)
mysql> insert into darat values ("kuda");
Query OK, 1 row affected (0,12 sec)
mysql> insert into darat values ("ular");
Query OK, 1 row affected (0,29 sec)
mysql> insert into darat values ("kucing");
Query OK, 1 row affected (0,06 sec)
mysql> select air from air UNION select darat from darat;
+----------+
| air |
+----------+
| katak |
| ikan mas |
| ular |
| ikan hiu |
| kuda |
| kucing |
+----------+
6 rows in set (0,00 sec)
mysql> select * from pegawai where gaji = (select max(gaji) from pegawai);
+-----+------------+--------+------------+--------+
| nip | nama | gaji | departemen | kota |
+-----+------------+--------+------------+--------+
| 4 | kadarisman | 960000 | akunting | sleman |
+-----+------------+--------+------------+--------+
1 row in set (0,05 sec)
0 comments