Quantcast
Channel: SCN : Discussion List - SAP HANA Developer Center
Viewing all articles
Browse latest Browse all 6412

SAP HANA SQL - WHERE clause with OR issues

$
0
0

Hello,

 

I have a HANA SQL statement question.

 


I have the following table defined:

 

CREATE COLUMN TABLE TEST_SCHEMA.TB_TEST_DATA
(ROW_ID                    INTEGER      PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
FLD1                      VARCHAR(255) NOT NULL,
FLD2                      VARCHAR(255) NOT NULL,
FLD3                      VARCHAR(255) NOT NULL,
FLD4                      VARCHAR(255) NOT NULL,
FLD5                      VARCHAR(255) NOT NULL,
FLD6                      VARCHAR(255) NOT NULL,
FLD7                      VARCHAR(255) NOT NULL,
FLD8                      VARCHAR(255) NOT NULL,
FLD9                      VARCHAR(255) NOT NULL,
FLD10                     VARCHAR(255));

 

 

I have loaded the above table with the following data:

 

insert into TEST_SCHEMA.TB_TEST_DATA
(ROW_ID, FLD1, FLD2, FLD3, FLD4, FLD5, FLD6, FLD7, FLD8, FLD9, FLD10)
VALUES (1, 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1');

 

insert into TEST_SCHEMA.TB_TEST_DATA
(ROW_ID, FLD1, FLD2, FLD3, FLD4, FLD5, FLD6, FLD7, FLD8, FLD9, FLD10)
VALUES (2,'VAL 1', 'VAL 1', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2');

 

insert into TEST_SCHEMA.TB_TEST_DATA
(ROW_ID, FLD1, FLD2, FLD3, FLD4, FLD5, FLD6, FLD7, FLD8, FLD9, FLD10)
VALUES (3,'VAL 2', 'VAL 2', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1', 'VAL 1');

insert into TEST_SCHEMA.TB_TEST_DATA


(ROW_ID, FLD1, FLD2, FLD3, FLD4, FLD5, FLD6, FLD7, FLD8, FLD9, FLD10)
VALUES (4,'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2', 'VAL 2');

 


The following UNION ALL select executes successfully returning all 3 rows:

 

SELECT *
   FROM TEST_SCHEMA.TB_TEST_DATA
  WHERE (FLD1 = 'VAL 1' AND FLD2 = 'VAL 1' AND FLD3 = 'VAL 1')
UNION ALL
SELECT *
   FROM TEST_SCHEMA.TB_TEST_DATA
  WHERE (FLD1 = 'VAL 1' AND FLD2 = 'VAL 1' AND FLD3 = 'VAL 2')
UNION ALL
SELECT *
   FROM TEST_SCHEMA.TB_TEST_DATA
  WHERE (FLD1 = 'VAL 2' AND FLD2 = 'VAL 2' AND FLD3 = 'VAL 1') 

 


When I combine the top 2 selects using OR in the WHERE clause and execute it all 2 rows are returned.

 

SELECT *
   FROM TEST_SCHEMA.TB_TEST_DATA
  WHERE (FLD1 = 'VAL 1' AND FLD2 = 'VAL 1' AND FLD3 = 'VAL 1')
     OR (FLD1 = 'VAL 1' AND FLD2 = 'VAL 1' AND FLD3 = 'VAL 2')

 

Result
------
ROW_ID;FLD1;FLD2;FLD3;FLD4;FLD5;FLD6;FLD7;FLD8;FLD9;FLD10
1;VAL 1;VAL 1;VAL 1;VAL 1;VAL 1;VAL 1;VAL 1;VAL 1;VAL 1;VAL 1
2;VAL 1;VAL 1;VAL 2;VAL 2;VAL 2;VAL 2;VAL 2;VAL 2;VAL 2;VAL 2

 


When I combine the bottom 2 selects using OR in the WHERE clause and execute it the database returns an error and crashes.

 

SELECT *
   FROM TEST_SCHEMA.TB_TEST_DATA
  WHERE (FLD1 = 'VAL 1' AND FLD2 = 'VAL 1' AND FLD3 = 'VAL 2')
     OR (FLD1 = 'VAL 2' AND FLD2 = 'VAL 2' AND FLD3 = 'VAL 1') 


The following error is received error:

 

Could not execute 'SELECT * FROM TEST_SCHEMA.TB_TEST_DATA WHERE (FLD1 = 'VAL 1' AND FLD2 = 'VAL 1' AND FLD3 = 'VAL 2') OR ...' in 4:29.324 minutes .
Data receive failed.

 


Does anyone know what might be causing this issue?

 

 

Our current configuration is as follows:
SAP HANA studio
Version: 1.00.81.0
Internal Version: 1.81.2 (1812)

 


Thanks,
Victoria


Viewing all articles
Browse latest Browse all 6412

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>