SQL: return group of rows where condition is true

Viewed 702

My dataset looks like this:

PNR    Action Code
-----+-------------
1    |  Book
1    |  Exchange
1    |  Cancel
2    |  Book
2    |  Exchange
3    |  Book
4    |  Book
4    |  Cancel

I am trying to return all the rows for PNRs where Action code was "Cancel". So in this case, all the rows for PNRs 1 & 4.

I tried to use a Where Clause but that won't be correct as it would return only the rows WHERE action code was "Cancel". My result should look like:

PNR    Action Code
-----+-------------
1    |  Book
1    |  Exchange
1    |  Cancel
4    |  Book
4    |  Cancel
7 Answers
Related