Question

In: Computer Science

Using MYSQL Workbench: ** Cannot use intersect only allowed to use inner join or in** Suppliers(sid:...

Using MYSQL Workbench:

** Cannot use intersect only allowed to use inner join or in**

Suppliers(sid: int, sname: VARCHAR(30), address: VARCHAR(50))

Parts(pid: int, pname: VARCHAR(30), color:VARCHAR(10))

Catalog(sid: int, pid:int, cost: double)

(Bolded names are primary keys)

1. Find distinct sids and snames of suppliers who supply a red part and a green part.

Solutions

Expert Solution

Table 1: Suppliers

CREATE TABLE `suppliers` (
`Sid` int(11) PRIMARY KEY,
`Sname` varchar(30) NOT NULL,
`Address` varchar(50) NOT NULL
);

INSERT INTO `suppliers` (`Sid`, `Sname`, `Address`) VALUES
(1, 'harry', 'Mumbai'),
(2, 'peter', 'Delhi'),
(3, 'Alex', 'Bengluru'),
(4, 'Aron', 'Goa');

Sid Sname Address
1 harry Mumbai
2 peter Delhi
3 Alex Bengluru
4 Aron Goa

Table 2: Parts

CREATE TABLE `parts` (
`pid` int(11) PRIMARY KEY,
`pname` varchar(30) NOT NULL,
`color` varchar(10) NOT NULL
);

IN22SERT INTO `parts` (`pid`, `pname`, `color`) VALUES
(1, 'gear', 'red'),
(2, 'seats', 'black'),
(3, 'mirror', 'green'),
(4, 'tyre', 'black');

pid pname color
1 gear red
2 seats black
3 mirror green
4 tyre black

Table 3: Catalog

CREATE TABLE `catalog` (
`Sid` int(11) NOT NULL,
`Pid` int(11) NOT NULL,
`Cost` double NOT NULL
);

INSERT INTO `catalog` (`Sid`, `Pid`, `Cost`) VALUES
(1, 3, 300),
(2, 4, 500),
(3, 1, 800),
(4, 2, 600);

ALTER TABLE `catalog`
ADD FOREIGN KEY (`Pid`) REFERENCES `parts` (`pid`),
ADD FOREIGN KEY (`Sid`) REFERENCES `suppliers` (`Sid`);

Sid Pid Cost
1 3 300
2 4 500
3 1 800
4 2 600

Question:Find distinct sids and snames of suppliers who supply a red part and a green part.

Query:

SELECT DISTINCT suppliers.Sid,suppliers.Sname from catalog

INNER JOIN parts on parts.pid=catalog.pid

INNER JOIN suppliers on suppliers.Sid=catalog.Sid

WHERE parts.color="red" or parts.color="green";

Sid Sname
1 harry
3 Alex

Related Solutions

This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that shows the table in 3rd Normal Form. Part two: Provide a summary of the steps you took to achieve 3rd Normal form. Include your rationale for new table creation, key selection and grouping of attributes. Table Details: The Anita Wooten Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at...
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12....
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12. SELECT the trackid, name and filesize (as shown in the bytes column) for all tracks that have a file size less than 2000000 and a GenreId of 1 or a file size less than 2000000 and a Genreid of 2 -- 13. Add a sort to the query from number 12 to sort by GenreID; -- 14. List all columns from the customer table...
Using MySQL Workbench to write and run the following steps, and take a screenshot for me!...
Using MySQL Workbench to write and run the following steps, and take a screenshot for me! Create a species table and a specimen table. In the species table, include attributes that reflect the name of the species, a general description of the species, and any other attributes you feel relevant. In the specimens table, include an ID for the specimen, a reference to the species which it is, the date which it was observed, and any relevant details like height,...
Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed....
Write a log-in log-out session using PHP, CSS, and HTML only. NO MYSQL and JavaScript allowed. 1. Need an HTML form and a login form; separate file. 2. need a CSS file to make it look good 3. Must store visitors' info in a .txt file and validate from there if the user exists before granting access to the dashboard. If the user does not exist, render the form to signup. If the user exists take them to their dashboard....
Part 2: Use MySQL Workbench to add a table to your database on the class server...
Part 2: Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table: Field Name Description Data Type Sample Value LoginID User’s login name varchar(10) Bob FirstName User’s first name varchar(50) Bob LastName User’s last name varchar(50) Barker picUrl Filename of the user’s picture varchar(50) bob.gif Bio User’s biography varchar(255) Bob is the best! LoginID should be the Primary Key of the table. Add at...
Use Workbench/Command Line to create the commands that will run the following queries/problem scenarios. Use MySQL...
Use Workbench/Command Line to create the commands that will run the following queries/problem scenarios. Use MySQL and the Colonial Adventure Tours database to complete the following exercises. 1. List the last name of each guide that does not live in Massachusetts (MA). 2. List the trip name of each trip that has the type Biking. 3. List the trip name of each trip that has the season Summer. 4. List the trip name of each trip that has the type...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence”...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence” with the following attributes (columns): A field named “id” which has data type auto_increment, A field named “country_name” which has data type varchar(50), and A field named “independence_date” which has type “date.” After you create the table, run the following SQL command: INSERT INTO independence(country_name, independence_date) VALUE (‘United States’,’1776-07-04’) Submit a 1-page Microsoft Word document that shows the following: The SQL command you used...
Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name...
Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name and phone (vendor_name and vendor_phone) in the state "CA" and the city "Los Angeles". here is the database tables CREATE TABLE general_ledger_accounts ( account_number INT PRIMARY KEY, account_description VARCHAR(50) UNIQUE ); CREATE TABLE terms ( terms_id INT PRIMARY KEY AUTO_INCREMENT, terms_description VARCHAR(50) NOT NULL, terms_due_days INT NOT NULL ); CREATE TABLE vendors ( vendor_id INT PRIMARY KEY AUTO_INCREMENT, vendor_name VARCHAR(50) NOT NULL UNIQUE, vendor_address1...
subject DBA use mysql workbench and select my guitar shop database as default schema Problem8 Write...
subject DBA use mysql workbench and select my guitar shop database as default schema Problem8 Write a script that implements the following design in a database named my_web_db:     users                                                       downloads                                                                 Products *user_id INT                                         * download_id INT                                                   * product_id INT                      *email_address VARCHAR(100)          * user_id INT                                                         * product_name VARCHAR(45) *first_name VARCHAR(45)                  *download_date DATETIME *last_name VARCHAR(45)                  * filename VARCHAR(50)                                                                *product_id INT Details In the downloads table, the user_id and product_id columns are the foreign keys. Include a statement to drop the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT