dbTalk Databases Forums  

using composite keys in an IN clause

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss using composite keys in an IN clause in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
cjflorian@gmail.com
 
Posts: n/a

Default using composite keys in an IN clause - 02-15-2010 , 02:18 AM






Hello, using DB2 version 9.7 I assumed the following would work. In
this example, tableA has a composite key on x,y.

select * from tableA where (x, y) IN ( ( 'x1', y1) )


but, DB2 throws this:

SQL0104N An unexpected token "," was found following ", y) in
( ('x1'".
Expected tokens may include: "+". SQLSTATE=42601


Is this not supported in DB2 or is my syntax wrong?

Thanks.

Reply With Quote
  #2  
Old   
Tonkuma
 
Posts: n/a

Default Re: using composite keys in an IN clause - 02-15-2010 , 05:13 AM






Use VALUES, like this ....
------------------------------ Commands Entered
------------------------------
WITH tableA(x,y) AS(
VALUES ('x1' , 1)
)
select * from tableA where (x, y) IN (VALUES ( 'x1', 1) )
;
------------------------------------------------------------------------------

X Y
-- -----------
x1 1

1 record(s) selected.


Because, right side of multiple values IN predicate should be
(fullselect).
values-clause make a fullselect.

Reply With Quote
  #3  
Old   
cjflorian@gmail.com
 
Posts: n/a

Default Re: using composite keys in an IN clause - 02-15-2010 , 09:59 AM



That worked. Thanks very much.



On Feb 15, 6:13*am, Tonkuma <tonk... (AT) fiberbit (DOT) net> wrote:
Quote:
Use VALUES, like this ....
------------------------------ Commands Entered
------------------------------
WITH tableA(x,y) AS(
VALUES ('x1' , 1)
)
select * from tableA where (x, y) IN (VALUES ( 'x1', 1) )
;
------------------------------------------------------------------------------

X *Y
-- -----------
x1 * * * * * 1

* 1 record(s) selected.

Because, right side of multiple values IN predicate should be
(fullselect).
values-clause make a fullselect.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.