Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Forked from knewter/gist:183963
Created September 9, 2009 18:53
Show Gist options
  • Save brandon-beacher/183970 to your computer and use it in GitHub Desktop.
Save brandon-beacher/183970 to your computer and use it in GitHub Desktop.
Here's my sample data set
mysql> SELECT tf.id, tf.authorization_id_response, tf.tran_type FROM transaction_feeds tf;
+-----+---------------------------+-----------+
| id | authorization_id_response | tran_type |
+-----+---------------------------+-----------+
| 239 | 223672 | 9120 |
| 240 | 223672 | 9220 |
| 241 | 223673 | 9120 |
+-----+---------------------------+-----------+
3 rows in set (0.00 sec)
I'd like to be write a query that will find all items in the table with
tran type 9120 which do not also have another entry in the table with the
same authorization_id_response.
SELECT id, authorization_id_response, tran_type
FROM transaction_feeds tf
WHERE NOT EXISTS (
SELECT authorization_id_response
FROM transaction_feeds
WHERE id != tf.id
AND authorization_id_response = tf.authorization_id_response
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment