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.

UNION not returning correct result

See original GitHub issue

AlaSQL is based on unpaid voluntary work. Thank you for taking the time to make it better.

Question about how to …

Something is not working as expected:

  • Describe the problem

    UNION does not work.

  • Provide code that replicates the problem

data1=[{a:'abc'},{a:'xyz'}]
data2=[{a:'123'},{a:'987'}]

alasql("select * from :a union select * from :b",{a:data1,b:data2})

— FF 95.01 Linux

[
  {},
  {},
  {
    "a": "abc"
  },
  {
    "a": "xyz"
  }
]

alasql.version “1.7.3-develop-0be167bcundefined”

----- Chrome 97.0 Linux


[
    {},
    {},
    {
        "a": "abc"
    },
    {
        "a": "xyz"
    }
]

alasql.version ‘1.7.3-develop-0be167bcundefined’

---- Node


> data1=[{a:'abc'},{a:'xyz'}]
[ { a: 'abc' }, { a: 'xyz' } ]
> data2=[{a:'123'},{a:'987'}]
[ { a: '123' }, { a: '987' } ]
> 
> alasql("select * from :a union select * from :b",{a:data1,b:data2})
[ {}, {}, { a: 'abc' }, { a: 'xyz' } ]
> alasql.version
'1.7.3-develop-0be167bcundefined'

---- How does it work in sqlite3

sqlite> create table one(a text);
sqlite> create table two(a text);
sqlite> insert into a values('abc'),('def');
sqlite> insert into two values('xyz'),('123');
sqlite> select * from one union select * from two;
123
abc
def
xyz



Maybe I’m using alasql incorrectly? I tried looking at some documentation in the wiki but the section on union is quite spartan.

Anyway, thanks a lot!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Tisamucommented, Oct 27, 2022

Nice ! Thanks for the tips. 😄

1reaction
Tisamucommented, Oct 26, 2022

Hello, sorry for giving no news.

Yep I’ve debugged a bit and it seems that the params of the first table are not passed to the union compilation method.

I’m still trying to understand all the compilation process of the query so I’m not sure where is the problem precisely.

I’m gonna work more on it this weekend. 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL returns less results when using UNION? - Stack Overflow
UNION will eliminate duplicate rows, whether they come between the two result sets or, as in your case, within just one result set....
Read more >
Union Select ALL query not returning all rows - MSDN
Hi stifter, Both UNION and UNION ALL, instead of UNION SELECT ALL, concatenate the result of two different SQLs.
Read more >
UNION not returning results - Oracle Communities
UNION not returning results ... In my query I get results from both the queries when run separately ... Probalbly union all will...
Read more >
SELECT query using UNION does not return the rows ...
A SELECT query using UNION does not return the rows expected. Is there a way to confirm that a unique customer record existed...
Read more >
How To Use Unions in SQL | DigitalOcean
The results returned through the UNION operation don't follow any particular order. To change that, you can utilize the ORDER BY clause. The ......
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