Download Document

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
E-Commerce Databases
Basic SQL Usage
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
1
Database
Management
Ver: 1.0
Queries Across Tables
SELECT products.productname, products.price
FROM `products`,`sales`,`customers`
WHERE products.prod_id = sales.prod_id AND sales.cus_id =
customers.cus_id AND customers.cus_id = 1;
• Displays name and price of products ordered
by customer with customer id 1
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
2
Queries Across Tables
1.
sales
Customer
3.
(cus_id)
(cus_id,prod_id)
products.productname,
products.price
Product
2.
(prod_id)
customers.cus_id = 1
4.
sales.cus_id = customers.cus_id
products.prod_id = sales.prod_id
• Writing a query bases on the tables structures
and relationships (see above)
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
3
Queries Across Tables
SELECT customers.surname, products.productname,
products.price
FROM `products`,`sales`,`customers`
WHERE products.prod_id = sales.prod_id AND sales.cus_id =
customers.cus_id AND customers.surname LIKE “Messnarz”;
• Displays customer name, product name and
price of products ordered by customer with
customer surname Messnarz
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
4
Queries Across Tables
SELECT customers.surname, products.productname,
products.price
FROM `products`,`sales`,`customers`
WHERE products.prod_id = sales.prod_id AND sales.cus_id =
customers.cus_id ;
• Displays all so far ordered products by
customers
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
5
Queries Across Tables
SELECT customers.surname, products.productname,
products.price
FROM `products`,`sales`,`customers`
WHERE products.prod_id = sales.prod_id AND sales.cus_id =
customers.cus_id
GROUP BY
products.productname, customers.surname;
• Displays all so far ordered products by
customers, grouped by the products
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
6
Queries Across Tables
• SELECT products.productname FROM
`products`,`sales`,`customers` WHERE products.prod_id =
sales.prod_id AND sales.cus_id = customers.cus_id;
• Displays all so far ordered products by
customers
• SELECT DISTINCT products.productname FROM
`products`,`sales`,`customers` WHERE products.prod_id =
sales.prod_id AND sales.cus_id = customers.cus_id;
• Displays all so far ordered products by
customers but shows each product chosen just
once
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
7
Run Queries From
phpMyAdmin
Open phpMyAdmin
• Enter queries, get advise about mistakes,
execute queries
• Query by examples (for unexperienced users)
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
8
INSERT Records
Syntax
Use the INSERT
statement to add new
rows of data to a single
table.
INSERT INTO table
(column-1, column-2, ... column-n)
VALUES
(value-1, value-2, ... value-n);
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
9
INSERT Records
• INSERT INTO customers VALUES
(2,'Damjan','elvis','Damjan','Ekert','ISCN A','Schieszstattgasse 4','A8010 Graz, Austria','+43 316 811198','+43 316
811312','[email protected]');
• Inserts the customer Ekert into the customer
table
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
10
Delete Records
Syntax
The SQL DELETE
statement is used to
delete one or more rows
from a table.
DELETE FROM table_reference
[WHERE predicates]
see code example in notes page.
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
11
Update Records
The SQL UPDATE
statement is used to
modify one or more
existing rows in a table.
Syntax
UPDATE table_reference
SET column_ref = update_value [, column_ref = update_value...]
[WHERE predicates]
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
12
Exercise 4 Master
Example 1 and 2
• Enter more example records using the
phpMyAdmin wizard
• Run and demonstrate first cross table queries
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
13
References
• SQL Queries for Mere Mortals: A Hands-On Guide to Data
Manipulation in SQL View Larger Image Michael J. Hernandez,
John L. Viescas
• Online SQL Manual, http://www.elevatesoft.com/manual.htm
E-COMMERCE JOBS
This project (Project number: HU/01/B/F/PP-136012)
is carried out with the financial support of the
Commssion of the European Communities
under the Leonardo da Vinci Programme
Database Management
14
Related documents