Question: So i can get data from a URL if i do it from with in my controller. But if i take that and move it into a factory it doesn't work. So what am i doing wrong?

```
angular.module('starter.notifications', [])

.factory('Notifications', function($http) {
  var link = "http://localhost:8000/notifications";
  var notifications = [];
  return {
    getAll: function()
    {
      return $http.get(link).success(function(data, status, headers, config) {
          notifications = data;
          return notifications;          
      });

    },

```

This code works if i move it into a controller, but why doesn't it work in a factory?

Answer: 
When you use a `LEFT JOIN`, if there's no matching row in table `B`, those columns will be `NULL`, so `B.date BETWEEN %s AND %s` will always be false. 

Put the restrictions on `B.date` in the `ON` clause, not the `WHERE` clause: `LEFT JOIN sales AS B ON A.item = B.item AND B.date BETWEEN %s AND %s`. This is the exception to the general rule that `ON` clauses should only contain comparisons between the tables being joined.
Since you are doing a `left join` some of the dates from B will be NULL. If you want all the results in the date range AND results with no associated record in B, you need to account for that:

```
WHERE B.date IS NULL OR B.date BETWEEN %s AND %s

```