Skip to content

Instantly share code, notes, and snippets.

@caseyamcl
Created October 11, 2011 13:18
Show Gist options
  • Save caseyamcl/1278048 to your computer and use it in GitHub Desktop.
Save caseyamcl/1278048 to your computer and use it in GitHub Desktop.
MySQL WHERE Exists
SELECT * FROM orders AS orders_table
WHERE EXISTS
(
SELECT * FROM orders_actions AS actions_table
WHERE actions_table.orders_id = orders_table.id
AND
(
actions_table.action = 'order_created'
OR actions_table.action = 'order_pending'
)
)
AND NOT EXISTS
(
SELECT * FROM orders_actions AS actions_table
WHERE actions_table.orders_id = orders_table.id
AND
(
actions_table.action = 'order_transmit_confirmation_received'
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment