The database stores the "email" and "page" of every "visit". I want to find the emails of the people who have visited the "checkout" page , possibly many times, but have NOT visited the "Thankyou" page. i.e abandoned carts; they got as far as checkoutm but never completed the purchase to get to the "Thankyou" page.
I want to return the list:
bob@bob.com
di@di.com
as the only two emails that have NOT visited the "Thankyou" page.
I know it must be some kind of self join on the visit table, but I'm struggling. Here is the data:
visit_id | visit_email | visit_page
----------------------------------------
1 | alice@alice.com | checkout
2 | alice@alice.com | Thankyou
3 | alice@alice.com | checkout
4 | alice@alice.com | checkout
5 | bob@bob.com | checkout
6 | chuck@chuck.com | checkout
7 | chuck@chuck.com | Thankyou
8 | di@di.com | checkout
9 | bob@bob.com | checkout
CREATE TABLE `visit` (
`visit_id` int(11) NOT NULL,
`visit_email` varchar(80) NOT NULL,
`visit_page` varchar(80) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `visit`
--
INSERT INTO `visit` (`visit_id`, `visit_email`, `visit_page`) VALUES
(1, 'alice@alice.com', 'checkout'),
(2, 'alice@alice.com', 'Thankyou'),
(3, 'alice@alice.com', 'checkout'),
(4, 'alice@alice.com', 'checkout'),
(5, 'bob@bob.com', 'checkout'),
(6, 'chuck@chuck.com', 'checkout'),
(7, 'chuck@chuck.com', 'Thankyou'),
(8, 'di@di.com', 'checkout'),
(9, 'bob@bob.com', 'checkout');