2 ms·
You aren't wrong. http://sqlfiddle.com/#!15/7eb3a/7 http://sqlfiddle.com/#!15/7eb3a/7 Here's a pretty simple/normalish way to handle the edge cases. This one
by withinboredom 3y ago
You aren't wrong.
http://sqlfiddle.com/#!15/7eb3a/7 http://sqlfiddle.com/#!15/7eb3a/7
Here's a pretty simple/normalish way to handle the edge cases. This one (without distinct) is far more consistent (wall-clock-wise, doesn't depend on caches): http://sqlfiddle.com/#!15/7eb3a/9 http://sqlfiddle.com/#!15/7eb3a/9
Note that order 2 is after order 4 in the example schema.
- withinboredom 3y agoIf you just need customer id and order id (and nothing from the original orders table), you can simplify it further http://sqlfiddle.com/#!15/7eb3a/10 http://sqlfiddle.com/#!15/7eb3a/10