# Anyone know why this query doesn't work in Noloco?

**URL:** <https://community.noloco.io/t/anyone-know-why-this-query-doesnt-work-in-noloco/356>\
**Category:** Ask for Help\
**Created:** [March 7, 2024, 9:53am UTC](https://community.noloco.io/t/anyone-know-why-this-query-doesnt-work-in-noloco/356 "2024-03-07T09:53:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![garyGHL](https://dub1.discourse-cdn.com/flex005/user_avatar/community.noloco.io/garyghl/32/555_2.png) [@garyGHL](https://community.noloco.io/u/garyGHL)\
**Post date:** [March 7, 2024, 9:53am UTC](https://community.noloco.io/t/anyone-know-why-this-query-doesnt-work-in-noloco/356/1 "2024-03-07T09:53:53Z")

</div>

Hello, I have a mysql query which works fine outside of Noloco but not inside and I cant quite work out why. It has unique fields but just displays a few records when there should be 100s.

I’ve tried setting l.id, year and various others to primary with no success.

```auto
SELECT  
  IfNull(l.LeadSource, 'GRAND TOTAL') AS LeadSource,
  Year(l.LeadDate) AS Year,
  Sum(Month(l.CompDate) = 1) AS Jan,
  Sum(Month(l.CompDate) = 2) AS Feb,
  Sum(Month(l.CompDate) = 3) AS Mar,
  Sum(Month(l.CompDate) = 4) AS Apr,
  Sum(Month(l.CompDate) = 5) AS May,
  Sum(Month(l.CompDate) = 6) AS Jun,
  Sum(Month(l.CompDate) = 7) AS Jul,
  Sum(Month(l.CompDate) = 8) AS Aug,
  Sum(Month(l.CompDate) = 9) AS Sep,
  Sum(Month(l.CompDate) = 10) AS Oct,
  Sum(Month(l.CompDate) = 11) AS Nov,
  Sum(Month(l.CompDate) = 12) AS Decb,
  Count(l.id) AS Leads,
  Count(MonthName(l.CompDate)) AS Complete,
  ROUND(Count(MonthName(l.CompDate)) * 100 / Count(l.id), 0) AS Converted,
  l.id AS LeadID
FROM
  tbl_lead l
  INNER JOIN tbl_clients c ON c.client_id = l.client_id
  LEFT JOIN users u ON u.username = c.Adviser
GROUP BY
  Year(l.LeadDate),
  l.LeadSource  
ORDER BY `Year` DESC

```

---

<div class="post-metadata">

**Author:** ![garyGHL](https://dub1.discourse-cdn.com/flex005/user_avatar/community.noloco.io/garyghl/32/555_2.png) [@garyGHL](https://community.noloco.io/u/garyGHL)\
**Post date:** [March 7, 2024, 12:08pm UTC](https://community.noloco.io/t/anyone-know-why-this-query-doesnt-work-in-noloco/356/2 "2024-03-07T12:08:46Z")

</div>

Managed to get this working, looks perfect as a pivot table built on a query.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/noloco/original/1X/2c6a367244d4750b9265114af2c2d256c04f4701.png)
