Académique Documents
Professionnel Documents
Culture Documents
Now answer the following questions: 1. Issue the following commands to the MYSQL database.
CREATE DATABASE if NOT EXISTS `test`; USE test; CREATE TABLE `users` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(100) DEFAULT NULL, `city` VARCHAR(100) DEFAULT NULL, `web` VARCHAR(100) DEFAULT NULL, `age` SMALLINT(6) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=latin1; INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (1,'Mike','New York','www.mike.com',25); INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (2,'John','Dallas','www.john.com',37); INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (3,'Anna','London','www.anna.com',24);
Page 1 of 4
INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (4,'David','Oxford','www.david.com',19); INSERT INTO `users`(`id`,`name`,`city`,`web`,`age`) VALUES (5,'Julia','New York','www.julia.com',20); 2. Now create a php page to insert a row in this table. 3.
Create another php page to view the contents of the table in the following format: ID: 1, Name:Mike, City:New York, Age:25 ID: 2, Name:John, City:Dallas, Age:37 ID: 3, Name:Anna, City:London, Age:24 ID: 4, Name:David, City:Oxford, Age:19 ID: 5, Name:Julia, City:New York, Age:20
Database Programming
Use the same database you created in the previous questions. Then answer the following questions. Note: For each question, write the answer in the empty space below the question. Suppose you are given the task to take public opinion on daily used products and thus analyze the market. Remember there are different companies in the market and a company can have multiple products. And also a product can be from different companies. For example, Uniliver and Keya Cosmetics are two different companies. But both of them sell Soap. Again Uniliver has many different products such as soap, face wash, shampoo etc. 1. You have to create a table which will have: Company Name, Product Name and public rating. And entry some data. For example, your table might look like:
Company Name Uniliver Keya Unilever Keya Keya Unilever P&G SQL statements:
Product Name Soap Shampoo Shampoo Soap Hand Wash Face Wash Soap 5 2 1 5 4 3 6
Public Rating
CREATE TABLE `product` ( `Company Name` VARCHAR(100) DEFAULT NULL, `Product Name` VARCHAR(100) DEFAULT NULL,
Page 2 of 4
2. Make a query to find out the number of different companies in the market.
Query results:
3. Make a query to find out the highest rated product for each company. Query statements: SELECT Company Name , Product Name FROM products WHERE Product Rating>=4
Query results: Uniliver Keya Keya P&G Soap Soap Hand Wash Soap 5 5 4 6
Page 3 of 4
4. Make a query to find out the company name for the highest rated product for each type of product. Query statements: SELECT Company Name FROM products WHERE (SELECT products WHERE Product Rating>=5 ) Product name FROM
Query results:
Page 4 of 4