-
Notifications
You must be signed in to change notification settings - Fork 666
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
Incorrect result when JOINing a subselect #832
Comments
Thank you for a very well described bug. We might need @agershun to give a hint to where the but could be located? |
The problem is in joining a subselect. Demonstration of the problem: http://jsfiddle.net/L11cnfbu/ For now you can get by if you put the result from your subselects into a (temporary) table (or in this example use the name Any inputs from @agershun why a join on a subselect will reset the list of column names in use? |
@mathiasrw Thank you for your very quick reply and work around suggested. Could you please let us know when we can expect the support for joining the subselect. Just curious, as it is highly required for one of our current project. |
All code here is added when people feel like contributing. There is no timeline. As soon as someone provides a PR with a fix I will release a new version. Another alternative is to pay to get the fix implemented. Let me know if that has any interest to you. |
not sure, is this the part of the code related to the issue? |
Hmmmmm. Interesting... |
+1 just ran into this today. |
Hi, a solution for this would be very appreciated! In the meanwhile, could you describe what is the most straight-ahead workaround? |
I haven't worked on this in a few month (I'll be getting back to it soon) but right now you have to materialize each of the sub-query result sets and pass them in using question marks in the final statement. var sub = alasql("SELECT * FROM my_sub_table WHERE...");
var sub2 = alasql("SELECT * FROM my_sub_table2 WHERE...");
var final = alasql("SELECT * FROM my_table ? ON (...) JOIN ? ON (...) WHERE ...", [sub, sub2]); This works and is pretty fast since it's all in memory and whatnot. |
I actually got the WITH
foo AS (
SELECT geo, SUM(num) AS num
FROM table1
WHERE
type = "B"
GROUP BY geo
),
bar AS (
SELECT geo, SUM(num) AS num
FROM table1
WHERE
type = "A"
GROUP BY geo
)
SELECT
foo.geo AS aggregation,
foo.num / bar.num AS val
FROM foo
JOIN bar
ON foo.geo = bar.geo; Thanks for your approach though, it can be very useful to reuse the temp tables. The strange thing is that using the (unsupported) sub-SELECT there is no error given, just the result of the last sub-SELECT. Is that intended? |
thank you for a great input @caesarsol |
Glad you found it useful! |
That would be awesome! |
is there any way to make this work using JS templates strings? I'm getting "cannot read property 'team' of undefined" - or is there a better way to do this?
edit: I was able to use this syntax
|
The right question here would be why the main query returns the subselect results. And bobviously this is because the join is not finished properly! This is relevant otherwise more confusion is brought instead as this is not related to columns... at this fisrt stage. Once solved there is another issue (second stage): the subselect support in joins is incomplete (in fact, there is no code to resolve defColumns and it takes a default resolution which is wrong to get the right data from the scope). Therefore, to resolve this issue = bug fix in joins + add missing code to support the use case. |
Hi Team,
I found that joins are not working(not giving the desired result). Please follow below steps to recreate problem.
Now when I run the following query
Result is:
But the expected result is(if u run in any other relational db)
Thanks
The text was updated successfully, but these errors were encountered: