Question

In: Computer Science

Experiment with SQL queries on 2 tables: Background: Normalized databases will involve data that is organized...

Experiment with SQL queries on 2 tables:

Background: Normalized databases will involve data that is organized into 2 or more tables. However, to answer queries, the data from 2 (or more) tables will need to be joined together to get the relevant information. Join operations in SQL are accomplished in the following manner:

  1. Indicate the tables involved in the query in the FROM clause
  2. Specify relationship/condition between columns in from the tables.

Exercise: For this part of the exercise the following tables have already been created and populated with data for you:

Product (pname, price, category, manufacturer)

Company (cname, stockPrice, country)

  1. Develop a SQL query (no join needed) to list all rows & columns in Company table (copy-paste your SQL statement and output in the space below):  

  1. Develop a SQL query (no join needed) to list all rows & columns in Product table (copy-paste your SQL statement and output in the space below):

  1. Develop a SQL query to list all names of products (pname) manufactured by Japanese companies (copy-paste your SQL statement and output in the space below):

  1. Develop a SQL query to list names and stock prices of companies that manufacture products cheaper than $200 (copy-paste your SQL statement and output in the space below):

Solutions

Expert Solution

for using JOIN there should be pimarykey in company table which later join with the foreign key of table product

CREATE TABLE `company` (

`cno` varchar(35) NOT NULL primarykey,

  `cname` varchar(35) NOT NULL,

  `stockPrice` int(11) NOT NULL,

  `country` varchar(35) NOT NULL

);

INSERT INTO `company` (`cname`, `stockPrice`, `country`) VALUES

('infosys', 1000, 'India'),

('tcs', 2000, 'India');

CREATE TABLE `product` (

`cno` varchar(35) NOT NULL FOREIGN KEY REFERENCES company(cno),

  `pname` varchar(35) NOT NULL ,

  `price` int(11) NOT NULL,

  `category` varchar(35) NOT NULL,

  `manufacturer` varchar(35) NOT NULL

);

INSERT INTO `product` (`pname`, `price`, `category`, `manufacturer`) VALUES

('abcd', 100, 'xyz', 'klm'),

('abc', 500, 'sdf', 'japanese');

1. list all rows & columns in company table

SELECT * FROM `company` WHERE 1

2. list all rows & columns in product table

SELECT * FROM `product` WHERE 1

3.list all names of products (pname) manufactured by Japanese companies

SELECT * FROM `product` WHERE manufacturer="japanese"

4. list names and stock prices of companies that manufacture products cheaper than $200

SELECT company.cname, company.stockPrice
FROM company
JOIN product ON company.cno=product.cno

WHERE product.price<200;


Related Solutions

Create a new SQL Developer SQL worksheet and create/run the following TWO (2) queries and save...
Create a new SQL Developer SQL worksheet and create/run the following TWO (2) queries and save your file as Comp2138LabTest1_JohnSmith100123456.sql (replace JohnSmith 100123456 with your name and student ID). Please place comment that includes your name and your student ID at the top of your script and number your queries using comments sections. Each query carries equal weight. A selection of the expected result set has been shown below for your convenience. Your output should match with this sample output....
Does the data contain errors? If so, write queries in SQL to find these errors and...
Does the data contain errors? If so, write queries in SQL to find these errors and propose a way to address the issues Theres a change of weight error (end weight-start weight) calculated wrong and a logical error
Part #4: Data normalization: Background: Data in a relational database is stored in a normalized form....
Part #4: Data normalization: Background: Data in a relational database is stored in a normalized form. Data normalization or just normalization is a strategy used to organize data into multiple related tables to reduce data redundancy while preserving data integrity. Exercise: Normalize the student data in the University table (sample data is shown further below) into 3 tables, namely, Student, Department, and Course. You do not need to populate data. Just illustrate the schema for the 3 tables. You may...
For Assignment 2, submit a word or pdf file with the SQL queries along with screenshots...
For Assignment 2, submit a word or pdf file with the SQL queries along with screenshots of the outputs. (It is ok if the whole problem cannot be answered, if possible, I just would like an idea of how to begin, thanks in advance!) 9. Write a query to count the number of invoices. 10. Write a query to count the number of customers with a balance of more than $500. 11. Generate a listing of all purchases made by...
Create tables according to the mapping. Add 2 records to each. Create 5 queries for database...
Create tables according to the mapping. Add 2 records to each. Create 5 queries for database of 3 table joins to use most of the tables or group of tables in database. You should not have tables that are of no use. Student(ssn, name, major) Class(classID, name, f_ssn) Faculty(ssn, name, office_num, dept_id) Department(Dept_id, office_num, f_ssn) Enroll(s_ssn, classID, grade) Professor(f_ssn, alma-mater, tenured) Instructor(f_ssn, term_degree, type) Lecture(classID, method) Lab(classID, location) Person(ssn, dob, gender)
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
EXPERIMENT 2: CREATING A PHYLUM KEY Data Tables Table 2: Phylum Taxonomic Key Prorifera Cnideria Platyhelminthes...
EXPERIMENT 2: CREATING A PHYLUM KEY Data Tables Table 2: Phylum Taxonomic Key Prorifera Cnideria Platyhelminthes Annelida Arthropoda Mollusca Echinodermata Chordata Questions 4. Were any of the features used in more than one phyla? If so, give an example of an organism from each phyla that shares the feature. 5. List three features from Table 1 that describe a Monarch butterfly (Danaus plexippus). Using the features you listed, determine what phyla it is classified in. PLEASE TYPE ANSWERS
Look at the following data tables obtained by students who performed the experiment in the past...
Look at the following data tables obtained by students who performed the experiment in the past and complete the following tasks: Using table 1 as your data set, build your Standard Curve by plotting protein concentration in the x-axis and absorbance in the y-axis. Also ask Excel to include the data trendline, the R2 value and the equation for the linear regression. Don’t forget to label your axis. Using the data provided by table 2 and the equation obtained from...
SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f)...
SQL A manufacturing company’s data warehouse contains the following tables. Region region_id (p) region_name super_region_id (f) 101 North America 102 USA 101 103 Canada 101 104 USA-Northeast 102 105 USA-Southeast 102 106 USA-West 102 107 Mexico 101 Note: (p) = "primary key" and (f) = "foreign key". They are not part of the column names. Product product_id (p) product_name 1256 Gear - Large 4437 Gear - Small 5567 Crankshaft 7684 Sprocket Sales_Totals product_id (p)(f) region_id (p)(f) year (p) month (p)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT