If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > where predicate

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-19-12, 08:46
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
where predicate

db2 ese 9.5 on p/linux
as I have never seen a statement like this and the result produced is correct, I was wondering if this is allowed and how is this translated

select ... from taba,tabb
where
(taba.col1,taba.col2) = (tabb.col1,tabb.col2) ......
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #2 (permalink)  
Old 01-19-12, 09:35
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I think that the syntax was not documented, but supported at least from DB2 9.1 for LUW.

Please see
comp.databases.ibm-db2 | Google Groups
Reply With Quote
  #3 (permalink)  
Old 01-19-12, 09:44
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
although being 60 and having worked with db2 for almost 30years.. never seen this before..
thanks for the update
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #4 (permalink)  
Old 01-20-12, 04:31
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
This is standard SQL stuff. It uses a <explicit row value constructor> (defined in Subclause 7.1 of the SQL 2003 standard).

In DB2 you could also do something like this:
Code:
SELECT ...
FROM ...
WHERE (col1, col2) = ( SELECT a, b FROM ... WHERE ...)
or this:
Code:
SELECT ...
FROM ...
WHERE (col1, col2) =ANY ( SELECT a, b FROM ... WHERE ...)
I would guess that "(taba.col1,taba.col2) = (tabb.col1,tabb.col2)" is working because of those quantified predicates or so...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 01-20-12, 07:45
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
I checked Information Center of different platforms.

Then I found that DB2 for z/OS and for iSeries suppot equal("=") or not equal("<>") of two (row-value-expression).

While DB2 for LUW doesn't.
The syntax include comparison of (row-value-expression) and (fullselect) in "Quantified predicate",
but not (row-value-expression) and (row-value-expression).


DB2 UDB for z/OS Version 8 > DB2 reference information > DB2 SQL > Language elements > Predicates

Basic predicate
Code:
>>-+-expression-+-=-------+-expression--------------------------+-><
   |            |    (1)  |                                     |
   |            +-<>------+                                     |
   |            +-<-------+                                     |
   |            +->-------+                                     |
   |            +-<=------+                                     |
   |            '->=------'                                     |
   |                             (1)                            |
   '-(row-value-expression)--+-=------+--(row-value-expression)-'
                             '-<>-----'

IBM i 7.1 Information Center > Database > Reference > SQL reference > Language elements > Predicates
--------------------------------------------------------------------------------

Basic predicate
A basic predicate compares two values or compares a set of values with another set of values.

Code:
>>-+-expression--+- = --+--expression---------------------------------+-><
   |             +- <> -+                                             |   
   |             +- < --+                                             |   
   |             +- > --+                                             |   
   |             +- <= -+                                             |   
   |             '- >= -'                                             |   
   +-(--row-value-expression--)--+- = --+--(--row-value-expression--)-+   
   |                             '- <> -'                             |   
   +-(--fullselect--)--+- = --+--(--row-value-expression--)-----------+   
   |                   '- <> -'                                       |   
   '-(--row-value-expression--)--+- = --+--(--fullselect--)-----------'   
                                 '- <> -'


DB2 Version 9.7 for Linux, UNIX, and Windows
--------------------------------------------------------------------------------
Basic predicate
Code:
>>-expression--+- = ------+----expression----------------------><
               |      (1) |                   
               +- <> -----+                   
               +- < ------+                   
               +- > ------+                   
               |      (1) |                   
               +- <= -----+                   
               |      (1) |                   
               '- >= -----'
DB2 Version 9.7 for Linux, UNIX, and Windows
--------------------------------------------------------------------------------
Quantified predicate

Code:
>>-+-expression1--+- = ------+--+-SOME-+--(fullselect1)------+-><
   |              |      (1) |  +-ANY--+                     |   
   |              +- <> -----+  '-ALL--'                     |   
   |              +- < ------+                               |   
   |              +- > ------+                               |   
   |              +- <= -----+                               |   
   |              '- >= -----'                               |   
   |    .-,---------------.                                  |   
   |    V                 |                                  |   
   '-(------expression2---+--)-- = --+-SOME-+--(fullselect2)-'   
                                     '-ANY--'
Reply With Quote
  #6 (permalink)  
Old 01-20-12, 08:04
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
on the page : Quantified predicate - starting example 5 : they show this kind of syntax..
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #7 (permalink)  
Old 01-20-12, 08:27
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Example 5 is a form of
(row-value-expression) = SOME (fullselect)

Example 6 is a form of
(row-value-expression) = ANY (fullselect)

Both are documented in syntax diagram of DB2 for LUW.

But, (row-value-expression) = (row-value-expression) is not ducumented.
Also, (row-value-expression) <> (row-value-expression) is not ducumented.

Equivalent predicate which conform to syntax of DB2 for LUW may be
(row-value-expression) = SOME (VALUES (row-value-expression) )


Quote:
DB2 Version 9.7 for Linux, UNIX, and Windows
--------------------------------------------------------------------------------
Quantified predicate

...

Example 5

SELECT * FROM TBLAB
WHERE (COLA,COLB+10) = SOME (SELECT COLX, COLY FROM TBLXY)

...

Example 6

SELECT * FROM TBLAB
WHERE (COLA,COLB) = ANY (SELECT COLX,COLY-10 FROM TBLXY)
...
Reply With Quote
  #8 (permalink)  
Old 01-20-12, 13:47
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
The form using "=SOME|ANY (fullselect)" is documented for DB2 LUW. Comparing 2 row value expressions is not - or I couldn't find it.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #9 (permalink)  
Old 01-20-12, 14:38
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Stolze,

Yes. That was I want to say in
Quote:
Originally Posted by tonkuma View Post
I think that the syntax was not documented, but supported at least from DB2 9.1 for LUW.

Please see
comp.databases.ibm-db2 | Google Groups

Example 1: Conform to syntax of DB2 for LUW like...
(row-value-expression) = SOME (fullselect), though the term row-value-expression was not used.

Note: "VALUES ('D11' , 16)" is a fullselect in DB2 for LUW. Please see fullselect - IBM DB2 9.7 for Linux, UNIX, and Windows
Code:
------------------------------ Commands Entered ------------------------------
SELECT empno 
     , firstnme || RTRIM(' ' || midinit) || ' ' || lastname AS fullname 
     , workdept
     , edlevel
 FROM  employee
 WHERE (workdept , edlevel) = SOME (VALUES ('D11' , 16) ) 
 ORDER BY
       empno
;
------------------------------------------------------------------------------

EMPNO  FULLNAME                       WORKDEPT EDLEVEL
------ ------------------------------ -------- -------
000060 IRVING F STERN                 D11           16
000150 BRUCE ADAMSON                  D11           16
000170 MASATOSHI J YOSHIMURA          D11           16
000190 JAMES H WALKER                 D11           16
000200 DAVID BROWN                    D11           16

  5 record(s) selected.
Example 2: I couldn't find a conformed syntax of DB2 for LUW. But, the result was same as Example 1.
Code:
------------------------------ Commands Entered ------------------------------
SELECT empno 
     , firstnme || RTRIM(' ' || midinit) || ' ' || lastname AS fullname 
     , workdept
     , edlevel
 FROM  employee
 WHERE (workdept , edlevel) = ('D11' , 16)
 ORDER BY
       empno
;
------------------------------------------------------------------------------

EMPNO  FULLNAME                       WORKDEPT EDLEVEL
------ ------------------------------ -------- -------
000060 IRVING F STERN                 D11           16
000150 BRUCE ADAMSON                  D11           16
000170 MASATOSHI J YOSHIMURA          D11           16
000190 JAMES H WALKER                 D11           16
000200 DAVID BROWN                    D11           16

  5 record(s) selected.

Last edited by tonkuma; 01-20-12 at 14:52. Reason: Add Note for Example 1.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On