-
Notifications
You must be signed in to change notification settings - Fork 647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GROUP BY returns 1 invalid result if no rows meet condition #79
Comments
Another issue with GROUP BY is that any field in the result that is not in the group is 'undefined'. MySQL simply returns the data from the first retrieved row.
Returns
Should be
|
Thank you! For the second question you should: var res = alasql('SELECT Type,Name FROM ? GROUP BY Type, Name',[...); or var res = alasql('SELECT Type,FIRST(Name) FROM ? GROUP BY Type',[...]); For the first question - sorry, it still in progress... |
Try this example in jsFiddle |
Yes, for first question, I am able to get away with this as I already always check for results:
|
Sorry, just a tweak on your example for others. (It works exactly as I would have expected it to from within mySQL)
returns [[{Type:"foo","FIRST(Name)":"bar"}]]
will return [[{Type:"foo",Name:"bar"}]] Is there a way you can test if the fields are requested naked, to automatically apply the FROM() function when used in a GROUP BY? Maybe in an upcoming version? |
👍 |
Is there a way you can test if the fields are requested naked, to automatically apply the FROM() function when used in a GROUP BY? I think, that the standard SQL reaction is to throw a error like "column is not found". I think, Alasql can check this, but only for SELECT with GROUP BY clause. Plus, it is hard to recognize these "naked" columns in expressions, like: SELECT mycol+1 FROM mytable GROUP BY othercol |
Is this issue resolved? |
There is news about this bug? Thanks in advance |
Well... its now returning Any help to resolve this would be awesome. |
adding HAVING count(*) > 0 seems to fix this problem |
If there is a query that has no results, but contains a GROUP BY, it returns one result regardless, with the data of "undefined"
The text was updated successfully, but these errors were encountered: