Professional Documents
Culture Documents
My SQL
My SQL
ALIAS
Berguna saat ingin mengubah nama kolom atau tabel ketika ingin melakukan select data, akan
berguna saat melakukan join.
select id as kode,
name as nama,
category as kategori,
description as deskripsi,
price as harga,
quantity as jumlah
from products;
p.name as nama,
p.category as kategori,
p.description as deskripsi,
p.price as harga,
p.qantity as jumlah
from products as p;
WHERE OPERATOR
select * from products where quantity > 75 and price > 25000;
select * from products where category = 'makanan' and price < 20000;
select * from products where quantity > 100 or price > 25000;
select * from products where (category = 'makanan' or quantity > 500) and price > 25000;
LIKE OPERATOR
NULL OPERATOR
BETWEEN
select * from products where price between 15000 and 20000;
select * from products where price not between 15000 and 20000;
IN
Order by cluse
Digunakan untuk mengurutkan data berdasarkan kolom yang dipilih, jenis urutan (ASC dan
DESC), bisa juga dilakukan untuk beberapa kolom
LIMIT CLAUSE
select * from products order by id limit 0, 5; -- 0, skip sedangkan 5 limit (limit pada angka ke-
dua)
Memanipulasi aritmatika
select id, name, price, price div 1000 as 'price in k' from products;
AUTO INCREMENT
Digunakan untuk menandai suatu primary key datanya diisi secara otomatis dari angka terakhir
+1, dengan auto increment kita tidak perlu memasukkan data primary ke, ini akan otomatis
dibuat oleh mysql
) engine = InnoDB;
('budi', 'nugraha'),
('joko', 'morro');
select last_insert_id();
STRING FUNCTION
select id,
lower(name) as lower_name,
upper(name) as upper_name,
length(name) as lenght_name
from products;
from products;