Question

In: Computer Science

Write a SQL statement which joins the parts table with the supplier table and lists the...

  1. Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query.
  2. Write a SQL statement which joins the parts table with the suppliers table and lists the part_name, supplier_name. You should return all rows from the parts table whether or not there are corresponding rows in the supplier table. You should use an outer join for this query.
  3. Write a SQL statement which joins the parts table with the supplier table and lists the part_no, part_name, supplier_name from parts and suppliers table. Only return the parts supplied by ‘Fred Smith ..'. You should use an inner join for this query.
  4. The faculty table contains faculty information and has a faculty_id as the primary key. The faculty_department table has the department assignments for faculty members and has the faculty_id from the faculty table as an exported key or foreign key. The department table has information about departments and has a department_id column as its primary key. The faculty_department table also has the exported key or foreign key for the department table.

Write a SQL statement to display faculty_id, first name, last name, department_id, department name (need to joins the faculty table with the faculty_department table with the department table. )Use an inner join for this query.

Solutions

Expert Solution

HI,

Below are SQL queries for you given statements:

SQL1:

SELECT s.supplier_name, p.part_name
FROM supplier s
INNER JOIN parts p ON s.supplier_id = p.supplier_id;

SQL2: I am using SQlite for the query and SQLite does not support outer join so i write the query like below for outer join..i write both type of queries one for SQlite and another other DB's

For other DB's:

SELECT  s.supplier_name, p.part_name from supplier s OUTER JOIN parts p WHERE
s.supplier_id = p.supplier_id

For SQlite:

SELECT s.supplier_name,
         p.part_name
         
FROM supplier s
LEFT JOIN parts p USING(supplier_id)
UNION ALL
SELECT s.supplier_name,
         p.part_name
FROM parts p
LEFT JOIN supplier s USING(supplier_id)
WHERE s.supplier_id IS NULL;

SQL3:

SELECT s.supplier_name, p.part_no, p.part_name
FROM supplier s
INNER JOIN parts p ON s.supplier_id = p.supplier_id WHERE s.supplier_name="Fred Smith"

SQL4:

SELECT fac.faculty_id, fac.faculty_fname, fac.faculty_lname, d.department_id, d.department_name
from faculty fac
INNER JOIN faculty_department fd ON fac.faculty_id = fd.faculty_id 
INNER JOIN department d ON d.department_id = fd.department_id

Thanks


Related Solutions

Write a SQL statement which joins the parts table with the supplier table and lists the...
Write a SQL statement which joins the parts table with the supplier table and lists the part_name, supplier_name for all parts in the part table. The supplier_id column in the suppliers table is the primary key in the suppliers table, and this key has been exported to the parts table where it is a foreign key. You should use an inner join for this query. Write a SQL statement which joins the parts table with the suppliers table and lists...
1. Write a SQL statement which joins the rider_student table with the rider_major table and lists...
1. Write a SQL statement which joins the rider_student table with the rider_major table and lists the rider student name and the name of the major (major_name) and the description of the major for which they are currently assigned. (You may use the SQL 'join' subclause, or simply express the join as part of the 'where' clause by indicating that you only want records where the primary key of the child table, rider_major, equals the corresponding foreign key of the...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for...
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for all product whose name includes both the words "silver" and "frame"
Use a single SQL statement to create a relational table and to load into the table...
Use a single SQL statement to create a relational table and to load into the table department name, subject code, year of running and session of running that offered by the departments. Note that a running subject offered by a department means a lecturer of the department has been assigned to teach the subject. Next, enforce the appropriate consistency constraints on the new table.    When ready use SELECT statement to list the contents of the relational table created and...
Write an SQL statement to show which customers boughtwhich items, and include any items that...
Write an SQL statement to show which customers bought which items, and include any items that have not been sold. Include LastName, FirstName, InvoiceNumber, InvoiceDate,ItemNumber, ItemDescription, ArtistLastName, and ArtistFirstName. Use a join using JOIN ON syntax, and sort the results by ArtistLastName and ArtistFirstName in ascending order (Hint: you have to use a RIGHT JOIN on the last step).
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade...
PL/SQL Write a PL/SQL block, using a Case Statement that prints a student’s letter     grade based on the value stored in a variable called grade. Use the ACC      grading system described in the course syllabus to create the block and set     the initial value of grade as 95. Use only one print statement and no      logical operators in your code. Assume a grade can exceed 100, but it      can’t be negative. Grade Scale: Grade Scale:...
Write an SQL command that creates a SHOP table. The table should have a shop_id, a shop_name, a shop_location
Write an SQL command that creates a SHOP table. The table should have a shop_id, a shop_name, a shop_location
In SQL we are working with functions 1. Write a SELECT statement that returns these columns...
In SQL we are working with functions 1. Write a SELECT statement that returns these columns from the Instructors table: a. The AnnualSalary column b. A column named MonthlySalary that is the result of dividing the AnnualSalary column by 12 c. A column named MonthlySalaryRounded that calculates the monthly salary and then uses the ROUND function to round the result to 2 decimal places 2. Write a SELECT statement that returns these columns from the Students table: a. The EnrollmentDate...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT