Unix Technical Forum

how to find the maximum id from two tables

This is a discussion on how to find the maximum id from two tables within the Informix forums, part of the Database Server Software category; --> The JBossAS tries to execute this query and gets a syntax error: SELECT MAX(TXID) FROM ( SELECT MAX(TXID) AS ...


Go Back   Unix Technical Forum > Database Server Software > Informix

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-20-2008, 10:57 AM
Frank Langelage
 
Posts: n/a
Default how to find the maximum id from two tables

The JBossAS tries to execute this query and gets a syntax error:
SELECT MAX(TXID) FROM (
SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS
UNION
SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES
)

The goal is to find the maximum txid out of two tables with one query.
I know I may create a view for the union select and select the max from
this view.
But I'd like to avoid this and use one query against the tables on my
IDS 10 server.

Regards,
Frank
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-20-2008, 10:57 AM
Richard Harnden
 
Posts: n/a
Default Re: how to find the maximum id from two tables

Frank Langelage wrote:
> The JBossAS tries to execute this query and gets a syntax error:
> SELECT MAX(TXID) FROM (
> SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS
> UNION
> SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES
> )
>
> The goal is to find the maximum txid out of two tables with one query.
> I know I may create a view for the union select and select the max from
> this view.
> But I'd like to avoid this and use one query against the tables on my
> IDS 10 server.


Informix insists that you say "table(multiset(select ...))", so you'll
need to rewrite you query as:

SELECT MAX(TXID)
FROM TABLE(
MULTISET(
SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS
UNION
SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES
)
)


hth

--
rh

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-20-2008, 10:57 AM
Art S. Kagel
 
Posts: n/a
Default Re: how to find the maximum id from two tables

Frank Langelage wrote:
> The JBossAS tries to execute this query and gets a syntax error:
> SELECT MAX(TXID) FROM (
> SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS
> UNION
> SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES
> )
>
> The goal is to find the maximum txid out of two tables with one query.
> I know I may create a view for the union select and select the max from
> this view.
> But I'd like to avoid this and use one query against the tables on my
> IDS 10 server.
>
> Regards,
> Frank


This will even work in 7.xx:

create function max2( one decimal, two decimal ) returning decimal;
if one > two then
return one;
else
return two;
end if;
end function;

select max2((SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS),
(SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES))
from systables
where tabid = 1;

Art S. Kagel

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:03 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com