Question

Using mySQL, tables at the end... This assignment uses the tables from the vets database. The...

Using mySQL, tables at the end...

This assignment uses the tables from the vets database. The goal of the assignment is to get you to think about joins- inner join and outer joins.  If you do a join, where you have the names of two or more tables in the From clause, then you must use the condition join syntax or the column name join.

Take care that you do not accidentally do a Cartesian product. If your result set contains a thousand rows ( or even a hundred rows for this assignment) you have probably done a Cartesian product and you need to correct the query.

Do not assume that these will all require outer joins because that was the topic for the week. Use an inner join if that will solve the task; use an outer join only if it is required.

Use the fewest tables possible for the queries. For example if I ask you to find animals with no exams, you need to use the exam headers table. But you do *not* need the exam details table. Sometimes adding extra tables makes your query less efficient; other times it makes your query incorrect.

The use of meaningful table aliases is required in assignments. The table names are fairly long and when you need to qualify a column, that expression gets longer and it can be harder to read. You define the table aliases within in each query. It can help to have a consistent set of table aliases to use. These are the ones I use; you can use them or different aliases that suggest the table.

clients cl

animals an

exam headers eh

exam details ed

Task 04: We want to find animals for which we have no exam records (use the exam header table). Show the client id, and last name and the an_id, name and type for every animal that does not have any exam records in the exam table. Sort by the client id and animal id.

Task 05: For this task use the same logic as in Task 03 except that your results should not display clients who have no animals.

Task 06: Display the client id and client last name and the animal id, name, and date of birth for all animals owned by a client who lives in New York or Massachusetts but do not display rows for any of the dogs, cats or birds.

Task 07: Display data about services we have in the services table that have a list price of $100 or more and that have not been used on any exam. Display the service id, list price, description and service type.

TABLES:

create table vt_staff (

    stf_id          numeric(6,0)

, stf_name_last   char(25)    not null

, stf_name_first char(25)    not null

, stf_job_title   char(25)    not null

);

create table vt_staff_pay (

    stf_id          numeric(6,0)

, stf_ssn         char(9)         not null

, stf_salary      numeric(8,2)     not null

, stf_hire_date   date            not null

);

create table vt_services(

    srv_id          numeric(6,0)

, srv_list_price numeric(6,2)   not null

, srv_desc        char(50)    not null

, srv_type        char(25)    not null

);

create table vt_animal_types(

    an_type         char(25)

);

create table vt_clients(

    cl_id           numeric(6,0)

, cl_name_last    char(25)    not null

, cl_name_first   char(25)    null

, cl_address      char(25)    not null

, cl_city         char(25)    not null

, cl_state        char(2)         not null

, cl_postal_code char(12)    not null

, cl_phone        char(12)    null

);

create table vt_animals(

    an_id           numeric(6,0)    

, an_type         char(25)    not null  

, an_name         char(25)    null

, an_dob          date            not null

, cl_id           numeric(6,0)     not null

);

create table vt_exam_headers(

    ex_id           numeric(6,0)    

, an_id           numeric(6,0)     not null

, stf_id          numeric(6,0)     not null

, ex_date         date            not null

);

create table vt_exam_details(

    ex_id           numeric(6,0)     not null

, line_item       numeric(6,0)     not null

, srv_id          numeric(6,0)     not null

, ex_fee          numeric(6,2)     not null

, ex_desc         char(50)    not null

);

Homework Answers

Answer #1

Task 04) select cl.cl_id,cl.cl_name_last,an.an_id,an.an_type,an.an_name
from clients cl,animals an
where cl.cl_id=an.cl_id
and an.an_id not in(select an_id from vt_exam_headers)
order by cl.cl_id,an.an_id;

Task 05)
select cl.cl_id,cl.cl_name_last,an.an_id,an.an_type,an.an_name
from clients cl,animals an
where cl.cl_id=an.cl_id
order by cl.cl_id,an.an_id;

Task 06) select cl.cl_id,cl.cl_name_last, an.an_id,an.an_name,an.an_dob
from clients cl, animals an
where cl.cl_id=an.an_id
and cl.cl_state in('New York','Massachusetts')
and an.an_type not in('dogs','cats','birds');

Task 07) select s.srv_id,s.srv_list_price,s.srv_desc,srv.srv_type
from vt_services s
where s.srv_id not in(select srv_id from vt_exam_details)
and s.srv_list_price>=100;

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Assignment 2 Instructions You need to access to the database and write SQL queries on the...
Assignment 2 Instructions You need to access to the database and write SQL queries on the following site: https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_in 1. Use INNER JOIN to create a report. In this report, list each customer’s CustomerID, CustomerName, and their each OrderID and each order’s OrderDate, if the customer has ever placed an order. You should use the Customers table and the Orders table in the database to complete this query.   2. Use INNER JOIN to create a report. In this report, list...
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...
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table....
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table. SQL provides two different techniques for querying data from multiple tables: • The SQL subquery • The SQL join As you will learn, although both work with multiple tables, they are used for slightly different purposes. We used WMCRM database which is what we created in Lab 4. Here is the summary of the database schema (where schema is used in its meaning of...
Having below tables: create table Student(sid char(10) primary key, sname varchar(20) not null, gpa float, major...
Having below tables: create table Student(sid char(10) primary key, sname varchar(20) not null, gpa float, major char(10), dob DATE); create table Course(cno char(10) primary key, cname varchar(20) not null, credits int, dept char(10)); create table Reg( sid references Student(sid) on delete cascade, cno references Course(cno) on delete cascade, grade char(2), primary key (sid, cno)); questions For each course, display the number of students who got each grade, ordered by the course and the letter grade. List the current age in...
Use the Donor database attached to the assignment answer the following: Question 1: Create a block...
Use the Donor database attached to the assignment answer the following: Question 1: Create a block to retrieve and display pledge and payment information for a specific donor. For each pledge payment from the donor, display the pledge ID, pledge amount, number of monthly payments, payment date, and payment amount. The list should be sorted by pledge ID and then by payment date. For the first payment made for each pledge, display “first payment” on that output row. 2 marks...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL CPTR HIST MATH RELB Data Type Text Text Text Text Text Number Currency Date/Time Text DEPT_TITLE Biology Computer Science History Mathematics Religion    Field Name DEPT_CODE DEPT_TITLE Data Type Text Text INSTRUCTIONS Use SQL commands to create the tables and enter the data shown above using MS Access. Write the following SQL statement given below: 1. 2. 3. 4. 5. 6. 7. 8. 9....
Assignment Instructions (MY WORK IN MYSQLBENCH)- Follow instructions in class to download and build a database...
Assignment Instructions (MY WORK IN MYSQLBENCH)- Follow instructions in class to download and build a database in your DBMS. Write and demonstrate queries (in-class) that do the following: Download the appropriate attached SQL file for your DBMS. Load the file into your database design tool and run it to build the Pine Valley Furniture Company database. This is the database that is used in the textbook examples for both Chapters 5 and 6. Write a query to show the price...
Perform SQL queries in the given data structure. write an SQL query that gives the number...
Perform SQL queries in the given data structure. write an SQL query that gives the number of courses taken for every student in the student table. For each instructor, show the instructor name and the number of sections that have been taught by that instructor. You do not need to include instructors who have never taught a section. List in order of decreasing the number of sections taught. Give the number of semester/year combinations in which sections have been offered....
Assignment 7 This is a two-part assignment. Students will create and submit 3 scripts. Here are...
Assignment 7 This is a two-part assignment. Students will create and submit 3 scripts. Here are the instructions: Before You need to Import the books_sc database via phpMyAdmin Script 1 Create a php file to connect to the books_sc database. You can name this file connect.php. This separate file will be ‘included’ in the other scripts, script 2 and script 2 Script 2 (25 points – to receive these points, you need to have the connect.php file created and submitted)...
Describe what the following query does using lyrics database with mysql. lyrics database is posted below...
Describe what the following query does using lyrics database with mysql. lyrics database is posted below 1.) select m.lastname, m.firstname, s.lastname from members m inner join salespeople s using (salesID) order by m.lastname asc; 2.) select studioID, studioname, base from salespeople sa inner join studios st on (sa.salesID = st.salesid) where base < 300 3.) SELECT artistName FROM Artists WHERE artistID IN (SELECT artistID FROM Titles) DROP TABLES IF EXISTS Artists,Genre, Members, Titles, Tracks,SalesPeople,Studios,XrefArtistsMembers; DROP TABLES IF EXISTS Authors,Publishers,Titles,Title_Authors,Royalties; DROP...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT