I have the following data in the booking table.
booking
id email price type areaid
1 [email protected] 70 type1 1
2 [email protected] 60 type2 2
3 [email protected] 50 type1 3
4 [email protected] 110 type1 3
5 [email protected] 90 type2 4
6 [email protected] 65 type2 1
7 [email protected] 84 type2 2
8 [email protected] 84 type1 2
I need to retrieve all email addresses from booking table which have only type2
and no other types. According to the data, only person2
meets this requirement.
How can I achieve this within a single query?
3
Answers
You can use above query for your task.
First group by clause using email then use having clause to filter the results after get grouped.
You can use
HAVING
:One more query for this problem is simple translation English to SQLish:
sqlize