0% found this document useful (0 votes)
136 views2 pages

Latihan SQL Dasar

1. The document provides instructions and examples for using basic SQL commands like SELECT, DISTINCT, WHERE, LIMIT, IN, BETWEEN, LIKE, UNION, and ALIAS in MySQL. 2. It begins by explaining how to set up MySQL using XAMPP and import a sample database, then gives examples of various SQL queries to retrieve and filter data. 3. The examples select fields from tables in the classicmodels sample database and apply conditions, sorting, limiting, and other SQL clauses to demonstrate the usage of the basic commands.

Uploaded by

Hari Aspriyono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views2 pages

Latihan SQL Dasar

1. The document provides instructions and examples for using basic SQL commands like SELECT, DISTINCT, WHERE, LIMIT, IN, BETWEEN, LIKE, UNION, and ALIAS in MySQL. 2. It begins by explaining how to set up MySQL using XAMPP and import a sample database, then gives examples of various SQL queries to retrieve and filter data. 3. The examples select fields from tables in the classicmodels sample database and apply conditions, sorting, limiting, and other SQL clauses to demonstrate the usage of the basic commands.

Uploaded by

Hari Aspriyono
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

D:\GoogleDrive\UNIVED 2017\MENGAJAR\TI - Basis Data\Script SELECT DISTINCT.sql Jumat, 13 Oktober 2017 09.

15
1 /* MEMULAI PRAKTIKUM DATABASE MYSQL */
2 1. Pastikan di komputer anda sudah terinstall MySQL
3 2. Supaya lebih mudah, Anda dapat install XAMPP di komputer anda
4 3. jalankan XAMPP-CONTROL
5 4. Start Module Apache dan MySQL
6 5. Buka Browser (Mozilla Firefox / Google Chrome)
7 6. Ketik url : http://localhost/phpmyadmin
8
9 /* Import Sample Database */
10 1. Klik Import di phpMyAdmin
11 2. Pilih file mysqlsampledatabase.sql yang sudah anda miliki
12 3. uncheck [] Enable foreign key checks
13 4. Klik Kirim
14
15 /* Menjalankan Perintah SQL */
16 1. Pada phpMyAdmin klik database classicmodels
17 2. Klik Menu SQL
18 3. Ketik Script/Perintah SQL
19 4. Klik Kirim
20
21 /* anda dapat mencoba perintah2 SQL di bawah ini : */
22
23 /* MEMILIH DATABASE YANG AKAN DIGUNAKAN */
24 USE classicmodels;
25
26 /* MENAMPILKAN SEMUA TABEL DALAM DATABASE */
27 SHOW TABLES;
28
29 /* SELECT */
30 SELECT * FROM employees;
31
32 /* DISTINCT */
33 SELECT DISTINCT lastname FROM employees ORDER BY lastname ASC;
34 SELECT DISTINCT state FROM customers;
35 SELECT DISTINCT state, city FROM customers WHERE state IS NOT NULL ORDER BY state,
city;
36 SELECT state, city FROM customers WHERE state IS NOT NULL ORDER BY state, city;
37 SELECT state FROM customers GROUP BY state;
38 SELECT DISTINCT state FROM customers;
39 SELECT COUNT(DISTINCT state) FROM customers WHERE country = 'USA';
40 SELECT DISTINCT state FROM customers WHERE state IS NOT NULL LIMIT 5;
41
42 /* WHERE */
43 SELECT lastname, firstname, jobtitle FROM employees WHERE jobtitle = 'Sales Rep';
44 SELECT lastname, firstname, jobtitle FROM employees WHERE jobtitle = 'Sales Rep' AND
officeCode = 1;
45
46 /* LIMIT */
47 SELECT customernumber, customername, creditlimit FROM customers ORDER BY creditlimit
DESC LIMIT 5;
48
49 /* IN */
50 SELECT officeCode, city, phone FROM offices WHERE country IN('USA', 'France');
51 SELECT officeCode, city, phone FROM offices WHERE country NOT IN('USA', 'France');
52 SELECT orderNumber, customerNumber, status, shippedDate FROM orders WHERE orderNumber
IN(SELECT orderNumber FROM orderdetails GROUP BY orderNumber HAVING SUM(
quantityOrdered * priceEach) > 60000);
53 SELECT orderNumber, customerNumber, STATUS, shippedDate FROM orders WHERE orderNumber
IN(10165, 10287, 10310);
54
55 /* BETWEEN */
56 SELECT productCode, productName, buyPrice FROM products WHERE buyPrice BETWEEN 90 AND
100;
57 SELECT productCode, productName, buyPrice FROM products WHERE buyPrice >= 90 AND
buyPrice <= 100;
58
59 /* LIKE */
60 SELECT employeeNumber, lastName, firstName FROM employees WHERE firstName LIKE 'a%';

-1-
D:\GoogleDrive\UNIVED 2017\MENGAJAR\TI - Basis Data\Script SELECT DISTINCT.sql Jumat, 13 Oktober 2017 09.15
61 SELECT employeeNumber, lastName, firstName FROM employees WHERE lastName LIKE '%on';
62 SELECT employeeNumber, lastName, firstName FROM employees WHERE lastname LIKE '%on%';
63 SELECT employeeNumber, lastName, firstName FROM employees WHERE firstname LIKE 'T_m';
64 SELECT employeeNumber, lastName, firstName FROM employees WHERE lastName NOT LIKE
'B%';
65 SELECT productCode, productName FROM products WHERE productCode LIKE '%\_20%';
66 SELECT productCode, productName FROM products WHERE productCode LIKE '%$_20%' ESCAPE
'$';
67
68 /* UNION */
69 SELECT customerNumber id, contactLastname NAME FROM customers UNION SELECT
employeeNumber id, firstname NAME FROM employees;
70 ( SELECT customerNumber, contactLastname FROM customers) UNION( SELECT employeeNumber
, firstname FROM employees ) ORDER BY contactLastname, customerNumber;
71
72 /* ALIAS */
73 SELECT CONCAT_WS(', ', lastName, firstname) FROM employees;
74 SELECT orderNumber 'Order no.', SUM(priceEach * quantityOrdered) Total FROM
orderdetails GROUP BY 'Order no.' HAVING total > 60000;
75

-2-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy