Commands and function of mysql

, , No Comments
Assalamualaikum....

Hello everybody.....................

in database, we often create command-command function maybe with function we will be understand hoho. this is it,,, all example and basic command for sintaks sql.
this is juts to remember for anything was I do with writing I remember it :)

change name Table:
RENAME TABLE `campus`.`value` TO `campus`.`new_value` ;

change content field (name)
UPDATE `campus`.`colleger` SET `name` = 'kashif khan' WHERE `colleger`.`idcolleger` = 'c010';

delete data field (id=c001)
DELETE FROM `colleger`.`colleger` WHERE `colleger`.`idcolleger` = 'c001


show content table (table colleger)
Select * from colleger

show a few of data field (table student field id_student and field name)
Select id_student, name, from student;

show content field/record (table lesson with code l001)
SELECT * FROM `lesson` WHERE lesson.code_ls = 'l001'

counting data for table (table student) [menghitung jumlah data pada tabel]
select count(*) from student;    => (count(*) without spasi)

Add content a field (table tbl_value field value)
SELECT sum( value ) FROM tbl_value;  =>type of data should number

show content data between value (table tbl_value field value)
select * from tbl_value where value between 80 and 90;

sort content of data a field (table student field name)
SELECT * FROM `student` order by name asc;(asc => AZ, desc =>ZA)

show bebased character which you want (data character “JO”)
SELECT * FROM `student` WHERE name like '%jo%'; (mark % character in front of or in rear)

show bebased character what you want (side left)
SELECT * FROM `student` WHERE left(name,1)=’a’; (abdul, aan, ani dll)

show bebased character what you want (side right)
SELECT * FROM `student` WHERE right(name,1)=’i’; (ani, joni,kiki, dll)

show bebased character what you want (middle)
SELECT * FROM `student` WHERE mid(name,2,1)=’d’; (ade, ida, edo, dll)

for type data numeric(double, integer, dll)
show max value for table
Select max(value) from tbl_value;  (table tbl_value field value)

show min value for table
Select min(value) from tbl_value;  (table tbl_value field value)

show value average
Select avg(value) from tbl_value;  (table tbl_value field value)

show one group with one field
select * from student group by majority;

show one of data more 1 table
Select nametable.field, namatabel.field from tabel1, tabel2 where namatabel.field=namatabel.field;
SELECT siswa.nis, siswa.nama, tbl_nilai.nilai FROM siswa, tbl_nilai where siswa.nis=tbl_nilai.nis;

know about count data in a table with source of toher data
select count(*), siswa.nis, tbl_nilai.nis from siswa,tbl_nilai where siswa.nis=tbl_nilai.nis;  =>Jumlah yang muncul adalah sesuai record di table tbl_nilai

create new table for table in already use
create view RELASI_NILAI as select siswa.nis, siswa.nama, tbl_nilai.kode_mp, tbl_nilai.nilai from siswa,tbl_nilai where siswa.nis=tbl_nilai.nis;

show record of the end of table
select * from report order by id desc limit 1

0 comments:

Post a Comment