tutorial: SQL

create table pelanggan

CREATE TABLE pelanggan (
kd_plg int(4) unsigned zerofill NOT NULL auto_increment,
nm_plg varchar(20) NOT NULL,
alamat varchar(50) NOT NULL,
PRIMARY KEY (kd_plg))
ENGINE=MYISAM AUTO_INCREMENT; 

entering information

INSERT INTO pelanggan (nm_plg, alamat)
VALUES
('slamet','jl.karang-tengah 24 demak'),
('vera','jl.kaliurang 2 yogyakarta');

query information

SELECT kd_plg, nm_plg, alamat FROM pelanggan

Selecting Data from different tables (INNER JOIN)

create table barang

CREATE TABLE barang (
kd_brg int(4) unsigned zerofill NOT NULL auto_increment PRIMARY KEY,
nm_brg varchar (30) NOT NULL,
harga double NOT NULL); 

entering information

INSERT INTO barang (nm_brg, harga)
VALUES
('LED samsung','1500'),
('Macbook','6000');

create table penjualan

CREATE TABLE penjualan (
no_jual int(4) NOT NULL auto_increment PRIMARY KEY,
kd_plg int(4) NOT NULL,
tgl DATE NOT NULL)
ENGINE=MYISAM;

entering information

INSERT INTO penjualan (kd_plg,tgl)
VALUES
(1, '2012-07-05')
(2, '2012-09-01');

create table penjualan_detil

CREATE TABLE penjualan_detil (
no_jual int(4) NOT NULL,
kd_brg int(4) unsigned zerofill NOT NULL,
harga double NOT NULL,
jumlah int(4) NOT NULL,
PRIMARY KEY (no_jual,kd_brg));
INSERT INTO penjualan_detil (no_jual,kd_brg)
VALUES
(1,1, '1500',2)
(1,2, '6000',5);
SELECT no_jual, nm_plg, alamat, tgl
FROM penjualan AS p
INNER JOIN 
pelanggan AS pl (p.kd_plg=pl.kd_plg)
Advertisements

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