Question

In: Computer Science

SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result...

SQL allows duplicate tuples in relations, and correspondingly defines the multiplicity of tuples in the result of joins. Which of the following queries always gives the same answer as the nested query shown below?

select * from R where a in (select S.a from S);

select R.* from R,S where R.a = S.a;

select R.* from R, (select distinct a from S) as S1 where R.a = S1.a;

select R.* from R,S where R.a = S.a and is unique R;

select distinct R.* from R,S where R.a = S.a;

Solutions

Expert Solution

Here let's undrstand using example i have 2 tables R as customer and S as invoice and both have common field cust_name.

Customer table

Invoice table:

Query 1

SELECT * FROM customer WHERE cust_num IN (SELECT cust_num FROM invoice);

It is concept of sub query. so in this inner query return all cust_num from invoice then customer returns all records which matches to result of subquery . here customer returns all those records which are in invoice.

result:

Query 2

SELECT R.* FROM customer R,invoice S WHERE R.cust_num = S.cust_num;

It is conept of inner join. here inner join of 2 tables customer and invoice so inner join returns all those records wich matches the condition. It retuns duplicate records also.

output:

Query 3:

SELECT R.* FROM customer R, (SELECT DISTINCT cust_num FROM invoice S) AS S1 WHERE R.cust_num = S1.cust_num;

It is concept of both inner join and subquery. in this first sub query is excecuted then result of that as a s1 then after it apply inner join with result of subquery. Here first its select disctinct records from invoice table then inner join with customer base on cust_num.

result:

Query 4:

select R.* from R,S where R.a = S.a and is unique R;

It is wrong syntax. we can not directly write unique on table.

Query 5:

SELECT DISTINCT R .* FROM customer R, invoice S WHERE R.cust_num = S.cust_num;

In this it is concept of inner join same as query 2 but its not return duplicate result because here we specified distinct record from customer so its filter out duplicate records.

result:


Related Solutions

what are some of the changes in consumer relations and public relations as a result of...
what are some of the changes in consumer relations and public relations as a result of globalization.
. Please write the SQL statements required to create the following relations, including appropriate versions of...
. Please write the SQL statements required to create the following relations, including appropriate versions of all primary and foreign key integrity constraints. (10 points) Books (isbn:CHAR(10), title: CHAR(20), author: CHAR(80), qty_in_stock: INTEGER, price: REAL, year_published: INTEGER) Customers (cid:INTEGER, cname: CHAR(80), address: CHAR(200)) Orders (ordernum:INTEGER, cid:INTEGER, order_date: DATE, cardnum:CHAR(16)) Orderlists (ordernum:INTEGER, isbn:CHAR(10), qty:INTEGER, ship_date:DATE)
how is database is common in every where in the realworld? DBMS allows substance and relations...
how is database is common in every where in the realworld? DBMS allows substance and relations among them to frame table , explain. DBMS supports an agreement that helps the user to keep the integrity of the database, explain please use simple words to understand to clear and make good examples. thank you
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND CORRECT ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
SQL ONLY. WRITE CLEAR AND SIMPLE ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN...
SQL ONLY. WRITE CLEAR AND SIMPLE ANSWERS. Consider the following relations (PRIMARY KEYS ARE WRITTEN IN BOLD) departments (dept_no, dept_name) dept_emp (emp_no, dept_no, from_date, to_date) dept_manager (dept_no, emp_no, from_date, to_date) employees (emp_no, birth_date, first_name, last_name, gender, hire_date) salaries (emp_no, salary, from_date, to_date) titles(emp_no, title, from_date, to_date) Write the following queries in SQL. No duplicates should be printed in any of the answers. List all the titles for which there is at least one employee having the title. Find the current...
Database Design and SQL The following relations keep track of airline flight information: Flights (flno: integer,...
Database Design and SQL The following relations keep track of airline flight information: Flights (flno: integer, from : string, to: string, distance: integer, departs: time, arrive: time, price: integer) Aircraft (aid: integer, aname : string, cruisingrange: integer) Certified (eid: integer, aid: integer) Employees (eid: integer, ename : string, salary: integer) The Employees relation describe pilots and other kinds of employees as well. Every pilot is certified for some aircraft and only pilots are certified to fly. Based on the schemas,...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve rows from any hotel with Family room types and price less than $150. use hoteldb; CREATE TABLE HOTEL ( hotelNo numeric primary key , name varchar(40) , address varchar(40) , city varchar(200) ); CREATE TABLE ROOM ( roomNo numeric Primary Key , hotelNo numeric References HOTEL , type varchar(20) , price dec(9,2) ); CREATE TABLE GUEST ( guestNo numeric primary key , name varchar(40)...
t/F/U . Comparative advantage allows for improved economic and social conditions as a result of immigration...
t/F/U . Comparative advantage allows for improved economic and social conditions as a result of immigration in a domestic economy. Draw a diagram/table showing improvements/digressions as a result of comparative advantage and immigration.
t/f/u comparative advantage allows for improved economic and social conditions as a result of immigration in...
t/f/u comparative advantage allows for improved economic and social conditions as a result of immigration in a domestic economy. Draw a diagram/table showing improvements/digressions as a result of comparative advantage and immigration whY?
t/f/u why? comparative advantage allows for improved economic and social conditions as a result of immigration...
t/f/u why? comparative advantage allows for improved economic and social conditions as a result of immigration in a domestic economy. Draw a diagram/table showing improvements/digressions as a result of comparative advantage and immigration.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT