Question

Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause)

Need to Create a Query to display products purchased by customers in Germany that were not purchased by customers in the US.

Customers PK Customer D CompanyName Contact Name Contact Title Address City State OrRegion PostalCode Country Phone char(5) v

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SELECT P.ProductID,P.ProductName FROM

Products P INNER JOIN OrderDetails OD ON OD.ProductID=P.ProductID

INNER JOIN Orders O ON O.OrderID = OD.OrderID

INNER JOIN Customers C ON C.CustomerID =O.CustomerID

WHERE C.Country ='Germany' AND

P.ProductID NOT IN (

SELECT P.ProductID FROM

Products P INNER JOIN OrderDetails OD ON OD.ProductID=P.ProductID

INNER JOIN Orders O ON O.OrderID = OD.OrderID

INNER JOIN Customers C ON C.CustomerID =O.CustomerID

WHERE C.Country ='US'

);

Explanation:-

Here, we are using SELECT to fetch data from the table.For product we are fetching only ProductId and ProductName.

We have used INNER JOIN to combine the tables.

We joined products with orderdetails ,then to orders and then customers.

For filtering data we are using WHERE clause in which we are checking for country to be Germany of customers and then we use AND operator to check for productid not in the list of products which is purchased by customer in US using NOT IN operator.

For getting that list of customers we used subquery which is similar to the main query and we fetched only productId.

Add a comment
Know the answer?
Add Answer to:
Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query because Northwind Traders wants to make sure that all orders are shipped within 10 days. Display any orders that were not shipped within 10 days. Include the OrderID, the OrderDate, and the number of days it took before the order was shipped. Customers PK Customer D CompanyName Contact Name Contact Title Address City State OrRegion PostalCode...

  • Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins...

    Question for SQL in MS SQL Server Management Studio (Please don't use where clause for Joins use from clause) Need to Create a Query because Northwind Traders has decided to increase their retail prices. Write a query that shows the product name, the current price, and the new price. Make sure the new price is listed to 2 decimal points. Follow below guidelines on new retail price: a.         If the category is beverages or dairy products, increase the price by...

  • The business process we are interested in is sales(i.e., selling products to customers). Develop a logical...

    The business process we are interested in is sales(i.e., selling products to customers). Develop a logical star- or snowflake-schema dimensional model. orders customers + PK FK orderdetails PK/EK OrderID PK/FK Products UnitPrice Quantity Discount PK OrderID Customer D FK Employeeld Order Date RequiredDate Shipped Date FK ShipVia Freight ShipName ShipAddress ShipCity ShipRegion ShipPostalCode Ship Country CustomerID CompanyName ContactName Contact Title Address City Region PostalCode Country Phone shipppers PK Shipperid CompanyName Phone Fax products PK ProductID + employees PK Employeeld LastName...

  • Questions are based on the Northwind database. a. A data dictionary (Excel file) that describes each...

    Questions are based on the Northwind database. a. A data dictionary (Excel file) that describes each of the tables. (Attached in question) b.    Write good, clean SQL that answers the following questions. c.     Separate your queries as I have done in the following example. End each query with a semicolon (;) and insert the word "go" between each query. Queries can span multiple lines if required. Select CustomerID from Customers; go Select Count(*) from Employees; go Select max(productID) from Products; 18. Produce...

  • Create the following SQL Server queries that access the Northwind database Same as problem 3 but,...

    Create the following SQL Server queries that access the Northwind database Same as problem 3 but, limit the list to all customers who placed 3 or more orders. The product id, product name, last date that the product was ordered for all items in the Grains/Cereals category. (Hint: Use MAX) The product ID, product name, and number of distinct customers who ordered that product in 1996 Thank you. Categories Customers Employees Order Details Orders Products Shippers 9 CategoryID CategoryName Description...

  • can someone solve these quick please and thank you! sql chapter 4 Query #1: List the...

    can someone solve these quick please and thank you! sql chapter 4 Query #1: List the company name, contact name, contact title and the phone number for customers who HAVE NOT put in an order. Use an outer join. Query #2: Create a listing displaying the employee first name, last name and the full name (First name space Last Name) of the person they report to (Supervisor). This is a self-join. If an employee does not report to anyone then...

  • The Northwind database created by Microsoft contains the sales data for a fictitious company called Northwind...

    The Northwind database created by Microsoft contains the sales data for a fictitious company called Northwind Traders, which imports and exports specialty foods from around the world. Here is the schema of the database: Products (ProductID, ProductName, SupplierID, CategoryID, QuantityPerUnit, UnitPrice, UnitsInStock, UnitsOnOrder, ReorderLevel, Discontinued); Suppliers (SupplierID, CompanyName, ContactName , ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax, HomePage); Categories (CategoryID, CategoryName, Description, Picture); Orders (OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia,  Freight, ShipName,ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry); Order_details (ID, OrderID,...

  • Display all customers. If a customer has placed any orders, also display the highest..... Tables: CREATE TABLE Sales.Cu...

    Display all customers. If a customer has placed any orders, also display the highest..... Tables: CREATE TABLE Sales.Customers ( CustomerId          INT          NOT NULL IDENTITY, CustomerName          NVARCHAR(50) NOT NULL, StreetAddress NVARCHAR(50) NULL, City          NVARCHAR(20) NULL, [State]          NVARCHAR(20) NULL, PostalCode         NVARCHAR(10) NULL, Country          NVARCHAR(20) NULL, Contact          NVARCHAR(50) NULL, Email         NVARCHAR(50) NULL, CONSTRAINT PK_Customers PRIMARY KEY(CustomerId) ); CREATE TABLE HR.Employees ( EmployeeId          INT          NOT NULL IDENTITY, FirstName         NVARCHAR(50) NOT NULL, LastName          NVARCHAR(50) NOT NULL, BirthDate         DATE         NOT NULL, HireDate          DATE         NOT NULL, HomeAddress...

  • If possible please just send the SQL statement. Thank you Each question within deliverable 3 must begin on a new page and be sure to document the question as the title of each item at the top o...

    If possible please just send the SQL statement. Thank you Each question within deliverable 3 must begin on a new page and be sure to document the question as the title of each item at the top of each page. Also, using a 12-point font, include the SQL statement and then provide a screen shot of each query. The screen shots must include both the SQL statement and the results for each item below based on the data entered in...

  • Database HW help!!!!!!! Provide the SQL statements for the following queries. (1) Provide the names and...

    Database HW help!!!!!!! Provide the SQL statements for the following queries. (1) Provide the names and phones of all swimmers currently in level (of id) 3. +-------+---------+---------------------------+ | FName | LName   | EMail                     | +-------+---------+---------------------------+ | Bobby | Khan    | theBKhan1 | | Clara | Johnson | ClaraJohnson_11 | +-------+---------+---------------------------+ 2 rows in set (0.00 sec) (2) Provide the names of swimmers who have signed up to participate in the event '100M Butterfly' of Meet id 1. +-------+---------+ | FName...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT