Reputation: 3
Suppose I have a log of Customers who come in on particular Days, like:
Cs day
-- ---
01 Tue
02 Tue
03 Wed
01 Wed
04 Thu
02 Thu
I need a query that returns only the #s of those Customers who were in both on Tue and on Wed. In this case, only Cs # 01.
Upvotes: 0
Views: 142
Reputation: 146557
And using subqueries...
Select distinct cs From Customers
Where Exists (Select * from Customers
Where day = 'Tue')
And Exists (Select * from Customers
Where day = 'Wed')
Upvotes: 0
Reputation: 48446
select distinct c1.Cs
from Customers c1
inner join Customers c2 on c2.Cs=c1.Cs
where c2.day='Tue' and c1.day='Wed'
Upvotes: 6