# Union query error

**URL:** <https://community.dremio.com/t/union-query-error/1461>\
**Category:** Uncategorized\
**Created:** [July 12, 2018, 8:48am UTC](https://community.dremio.com/t/union-query-error/1461 "2018-07-12T08:48:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjbhjsj](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bjbhjsj](https://community.dremio.com/u/bjbhjsj)\
**Post date:** [July 12, 2018, 8:48am UTC](https://community.dremio.com/t/union-query-error/1461/1 "2018-07-12T08:48:44Z")

</div>

hi,supporters:  
I had found the problem when I used the dremio2.0.1 .can you help me ?  
enviroment: dremio2.0.1 (1 master ,2 executer)  
query SQL:

select u.\* from (select \* from “68”.csp.jmsb union select \* from “68”.csp.stsb ) u

**_ERROR INFORMATION_**

DATA\_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query. sql SELECT \* FROM `csp`.`jmsb` LIMIT 2000 OFFSET 0 UNION SELECT \* FROM `csp`.`stsb` LIMIT 2000 OFFSET 0 plugin 68 SqlOperatorImpl JDBC\_SUB\_SCAN Location 1:0:4 SqlOperatorImpl JDBC\_SUB\_SCAN Location 1:0:4 Fragment 1:0 [Error Id: 4e2de7e1-9036-4ff0-8f83-74c558a5db8d on node2:-1] (java.sql.SQLException) (conn:127358) Incorrect usage of UNION and LIMIT org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get():179 org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException():118 org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue():247 org.mariadb.jdbc.MariaDbStatement.executeInternal():322 org.mariadb.jdbc.MariaDbStatement.executeQuery():492 com.dremio.exec.store.jdbc.JdbcRecordReader.setup():175 com.dremio.exec.store.CoercionReader.setup():109 com.dremio.sabot.op.scan.ScanOperator$1.run():188 com.dremio.sabot.op.scan.ScanOperator$1.run():184 java.security.AccessController.doPrivileged():-2 javax.security.auth.Subject.doAs():422 org.apache.hadoop.security.UserGroupInformation.doAs():1807 com.dremio.sabot.op.scan.ScanOperator.setupReaderAsCorrectUser():184 com.dremio.sabot.op.scan.ScanOperator.setupReader():176 com.dremio.sabot.op.scan.ScanOperator.setup():162 com.dremio.sabot.driver.SmartOp$SmartProducer.setup():560 com.dremio.sabot.driver.Pipe$SetupVisitor.visitProducer():79 com.dremio.sabot.driver.Pipe$SetupVisitor.visitProducer():63 com.dremio.sabot.driver.SmartOp$SmartProducer.accept():530 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.Pipeline.setup():58 com.dremio.sabot.exec.fragment.FragmentExecutor.setupExecution():331 com.dremio.sabot.exec.fragment.FragmentExecutor.run():227 com.dremio.sabot.exec.fragment.FragmentExecutor.access$800():83 com.dremio.sabot.exec.fragment.FragmentExecutor$AsyncTaskImpl.run():577 com.dremio.sabot.task.AsyncTaskWrapper.run():92 com.dremio.sabot.task.slicing.SlicingThread.run():71 Caused By (java.sql.SQLException) Incorrect usage of UNION and LIMIT Query is: SELECT \* FROM `csp`.`jmsb` LIMIT 2000 OFFSET 0 UNION SELECT \* FROM `csp`.`stsb` LIMIT 2000 OFFSET 0 org.mariadb.jdbc.internal.util.LogQueryTool.exceptionWithQuery():113 org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery():167 org.mariadb.jdbc.MariaDbStatement.executeInternal():316 org.mariadb.jdbc.MariaDbStatement.executeQuery():492 com.dremio.exec.store.jdbc.JdbcRecordReader.setup():175 com.dremio.exec.store.CoercionReader.setup():109 com.dremio.sabot.op.scan.ScanOperator$1.run():188 com.dremio.sabot.op.scan.ScanOperator$1.run():184 java.security.AccessController.doPrivileged():-2 javax.security.auth.Subject.doAs():422 org.apache.hadoop.security.UserGroupInformation.doAs():1807 com.dremio.sabot.op.scan.ScanOperator.setupReaderAsCorrectUser():184 com.dremio.sabot.op.scan.ScanOperator.setupReader():176 com.dremio.sabot.op.scan.ScanOperator.setup():162 com.dremio.sabot.driver.SmartOp$SmartProducer.setup():560 com.dremio.sabot.driver.Pipe$SetupVisitor.visitProducer():79 com.dremio.sabot.driver.Pipe$SetupVisitor.visitProducer():63 com.dremio.sabot.driver.SmartOp$SmartProducer.accept():530 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.StraightPipe.setup():102 com.dremio.sabot.driver.Pipeline.setup():58 com.dremio.sabot.exec.fragment.FragmentExecutor.setupExecution():331 com.dremio.sabot.exec.fragment.FragmentExecutor.run():227 com.dremio.sabot.exec.fragment.FragmentExecutor.access$800():83 com.dremio.sabot.exec.fragment.FragmentExecutor$AsyncTaskImpl.run():577 com.dremio.sabot.task.AsyncTaskWrapper.run():92 com.dremio.sabot.task.slicing.SlicingThread.run():71

---

<div class="post-metadata">

**Author:** ![bjbhjsj](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bjbhjsj](https://community.dremio.com/u/bjbhjsj)\
**Post date:** [July 12, 2018, 8:49am UTC](https://community.dremio.com/t/union-query-error/1461/2 "2018-07-12T08:49:38Z")

</div>

the dataSource Type is mysql 5.7.20-18

---

<div class="post-metadata">

**Author:** ![jason](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/jason/32/3129_2.png) [@jason](https://community.dremio.com/u/jason)\
**Post date:** [July 13, 2018, 3:21pm UTC](https://community.dremio.com/t/union-query-error/1461/3 "2018-07-13T15:21:09Z")

</div>

Hi there,

Could you confirm whether `“68”.csp.jmsb` and `“68”.csp.stsb` are virtual or physical datasets in Dremio? If they are virtual, please share the definition of these VDSs.

Also could you share the profile of the failed query? See the link below how to do that.

> **[How To Share A Query Profile](https://www.dremio.com/tutorials/share-query-profile-dremio/)**
>
> Tutorial explaining how to share a query profile in Dremio.

---

<div class="post-metadata">

**Author:** ![bjbhjsj](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bjbhjsj](https://community.dremio.com/u/bjbhjsj)\
**Post date:** [July 14, 2018, 1:21am UTC](https://community.dremio.com/t/union-query-error/1461/4 "2018-07-14T01:21:50Z")

</div>

hi jason  
nice to see your reply. the “68”.csp.jmsb and the “68”.csp.jmsb are two physical table.  
I supplement the problem when I click the “preview” button is report the error ,but when i  
click the “run” , it can work normally.

---

<div class="post-metadata">

**Author:** ![anthony](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/anthony/32/670_2.png) [@anthony](https://community.dremio.com/u/anthony)\
**Post date:** [July 14, 2018, 9:16pm UTC](https://community.dremio.com/t/union-query-error/1461/5 "2018-07-14T21:16:37Z")

</div>

There seems to be a SQL translation problem with the use of `limit` & `union` in your specific version of MySQL. When you use “preview” button, Dremio inserts a `limit` so that you can preview and see your data very quickly. When you use the “run” button, it runs the query on the full dataset so thereby doesn’t add a `limit`.

Unfortunately I am unable to repro this error with my own version of MySQL. In the interim, I would recommend just building a VDS off that union query and continuing workflow from there.
