question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GROUP BY returns 1 invalid result if no rows meet condition

See original GitHub issue

If there is a query that has no results, but contains a GROUP BY, it returns one result regardless, with the data of “undefined”

console.log(alasql('SELECT Name FROM ? WHERE 1=0 GROUP BY Name',[[{Name:'test'}]]));
returns: [{Name: 'undefined'}] but should be []

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
tran4ocommented, Feb 17, 2020

adding HAVING count(*) > 0 seems to fix this problem

0reactions
mathiasrwcommented, Jun 11, 2018

Well… its now returning [{}] instead of the original problem - but its still not correct.

Any help to resolve this would be awesome.

http://jsfiddle.net/t780pnz1/

Read more comments on GitHub >

github_iconTop Results From Across the Web

GROUP BY returns 1 invalid result if no rows meet condition #79
Another issue with GROUP BY is that any field in the result that is not in the group is 'undefined'. MySQL simply returns...
Read more >
Select No Rows If Any Row Meets A Condition? - Stack Overflow
Something like this ? SELECT * FROM SOMETABLE WHERE ID = 1 AND NOT EXISTS (SELECT 1 FROM SOMETABLE WHERE INDICATOR = 'X')....
Read more >
7 Common GROUP BY Errors - LearnSQL.com
1. Forgetting GROUP BY with Aggregate Functions. You use SELECT statements with the GROUP BY clause when you want to group and organize...
Read more >
Select rows within group before condition is met
A single window function in a subquery should do the trick: SELECT * FROM ( SELECT *, count(*) FILTER (WHERE height = 0)...
Read more >
Possible Wrong Results of the Group By Clause - SQLite Forum
Should not it returns two rows or zero row? ... sqlite> select * from t2 group by 1; -- unique values in column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found