Menggabungkan Data dari Dua Tabel yang Berbeda Tetapi Field Sama [closed]

Saya mau nanya, gimana ya cara menggabungkan data dari tabel yg berbeda tapi fieldnya sama.
Misalnya ada dua tabel;

1. Booking (Orderan yang sudah/sedang di booking, packing, dan Batal),
2. Retur (Orderan yang di kembalikan).

Field nya sama hanya agar lebih mengetahui sebanyak mana yg di retur (Biar terpisah).

Kalau itu perintah mysql-nya gimana ya?

Struktur tabel Booking,
+--------------+-------------------------------------------------+-----+---------+
| Field        | Type                                            | Key | Default |
+--------------+-------------------------------------------------+-----+---------+
| id_packing   | int(20)                                         | PRI | NULL    |
| id_penjual   | varchar(50)                                     |     | NULL    |
| nm_pembeli   | varchar(50)                                     |     | NULL    |
| alamat       | text                                            |     | NULL    |
| marketplace  | enum('Bukalapak','Tokopedia','Lazada','Shopee') |     | NULL    |
| status_order | enum('Belum','Packed','Terkirim','Batal')       |     | Belum   |
| jam_booking  | time                                            |     | NULL    |
| tgl_booking  | date                                            |     | NULL    |
+--------------+-------------------------------------------------+-----+---------+

Struktur tabel Retur,
+--------------+-------------------------------------------------+-----+
| Field        | Type                                            | Key |
+--------------+-------------------------------------------------+-----+
| id_packing   | int(20)                                         | PRI |
| id_penjual   | varchar(50)                                     |     |
| nm_pembeli   | varchar(50)                                     |     |
| alamat       | text                                            |     |
| marketplace  | enum('Bukalapak','Tokopedia','Lazada','Shopee') |     |
| status_order | enum('Return')                                  |     |
| jam_booking  | time                                            |     |
| tgl_booking  | date                                            |     |
| jam_return   | time                                            |     |
| tgl_return   | date                                            |     |
+--------------+-------------------------------------------------+-----+
avatar syahid246

@syahid246

39 Kontribusi 79 Poin


Jawaban Terpilih

Sudah fix, pakai union
(SELECT id_packing, id_penjual, nm_pembeli,
        alamat, marketplace, status_order,
        jam_booking, tgl_booking
FROM booking)
UNION
(SELECT id_packing, id_penjual, nm_pembeli,
        alamat, marketplace, status_order,
        jam_booking, tgl_booking
FROM retur)
ORDER BY CONCAT(tgl_booking, jam_booking)
avatar syahid246

@syahid246

39 Kontribusi 79 Poin

Jawaban

Kenapa tidak gunakan nama tabelnya saja? Jadi misal
Booking.id_packing

Atau direname dulu jika kepanjangan
SELECT B.id_packing FROM Booking AS B


(Masukan saja, sepertinya kedua tabel itu terlalu redundan. Jika itu saya, mungkin sudah digas duluan oleh dosen saya :D )
avatar kodergan

@kodergan

46 Kontribusi 55 Poin


Sudah fix, pakai union
(SELECT id_packing, id_penjual, nm_pembeli,
        alamat, marketplace, status_order,
        jam_booking, tgl_booking
FROM booking)
UNION
(SELECT id_packing, id_penjual, nm_pembeli,
        alamat, marketplace, status_order,
        jam_booking, tgl_booking
FROM retur)
ORDER BY CONCAT(tgl_booking, jam_booking)
avatar syahid246

@syahid246

39 Kontribusi 79 Poin


Login untuk gabung berdiskusi