Example of SQL Inner Join

·

Customers (ssNum, name, address)
Orders (ssNum, id)
Products (id, pprice, description)

a)
Select the names of all customers who have orders.

SELECT DISTINCT name
FROM Customers INNER JOIN Orders ON
Customers.ssNum = Orders.ssNum;

b)
Select all the products with the description “Phone” that have been ordered

SELECT DISTINCT Product s.*
FROM Orders INNER JOIN Products ON
Products.id = Order s.id
WHERE description = ‘Phone’;

c)
Select the addresses of the customers, who have ordered products worth more than 800, and the related product info.

SELECT DISTINCT c.address, p.*
FROM Customers c INNER JOIN Orders o ON c.ssNum = o.ssNum
INNER JOIN Products p ON o.id = p.id
WHERE pprice > 800;

Live Traffic Feed

About this blog

Site Sponsors