I have one (possibly two) troublesome raw sql queries in a python flask API. I think the first sql query is causing this error, but I am by no means a master at sql. The database is DB2. The full error is as follows: “[SQL0199] Keyword UNION not expected. Valid tokens: FOR USE SKIP WAIT WITH OPTIMIZE.”. Here are my first and second sql query
First query
SELECT
PRDATA as the_date,
PREDR as csr,
PRQTY as quantity,
PRORD# as order_data,
PREXT as ext
FROM DATA.DATATABLE
WHERE CUST = {customer_number}
limit {Limit} offset {offset_count}
union all
SELECT
PRDATA as the_date,
PREDR as csr,
PRQTY as quantity,
PRORD# as order_data,
PREXT as ext
FROM DATA.DATATABLE
WHERE CUST = {customer_number}
limit {Limit} offset {offset_count}
Second query
SELECT COUNT(*)
from DATA.DATATABLE
WHERE PRCUST# = {customer_number}
UNION ALL
SELECT COUNT(*)
from DATA.DATATABLE
WHERE PRCUST# = {customer_number}
Like I said, I am not master as SQL so any advice or a pointer towards something I could check out would be much appreciated, thanks!
Advertisement
Answer
Finally figured it out. It was with the first query, I removed the firstlimit {Limit} offset {offset_count}
and left the second one after the union all. I suppose since I was using a union all it was thinking of it as a duplicate maybe and throwing that error. Not entirely sure