Hook
Hook

Reputation: 325

SQL - Obtain all invoices of people that once had an invoice over $100

So I've got a basic SQL question that I can't seem to work out. The query is: "Obtain all the invoices of customers who have ever had an invoice over $100".

Here's the SQL fiddle I've been using: http://sqlfiddle.com/#!6/99169/22

The things I've been trying is like:

SELECT * from Invoice I 
INNER JOIN Customer C ON C.id=I.customer where I.inv_total > 100.00; 

But it's not working... any help is appreciated :)

Upvotes: 1

Views: 54

Answers (1)

dotnetom
dotnetom

Reputation: 24901

You can use such query:

SELECT * from Invoice I 
INNER JOIN Customer C ON C.id=I.customer 
WHERE C.id IN (SELECT customer from Invoice WHERE inv_total > 100) 

In your where condition you filter customers by invoices that are over 100.

Upvotes: 1

Related Questions