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 > Informix > select first and union

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-10, 15:22
dtrobert dtrobert is offline
Registered User
 
Join Date: Feb 2010
Posts: 29
select first and union

Hi,
I was wondering if anyone found a good workaround to collecting a limited number of rows from a union-style query. I basically have something like


select first 500 col1, col2, col3...
union
select first 500 col1, col2, col3...
order by col1

and get the result

Cannot use 'first', 'limit' or 'skip' in this context.
Reply With Quote
  #2 (permalink)  
Old 09-24-10, 05:33
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
Its not possible to use First in the second statement, but you can use it in the first one:
select first 500 col1, col2, col3...
union
select first 500 col1, col2, col3...
order by col1

You can solve the problem with a temp table:
Code:
select first 5 customer_num from customer order by customer_num desc
into temp tmp1;

insert into tmp1 select first 5 customer_num from customer;

select * from tmp1 order by customer_num;
You get the first and last 5 customer_num's.
Reply With Quote
  #3 (permalink)  
Old 09-24-10, 12:32
dtrobert dtrobert is offline
Registered User
 
Join Date: Feb 2010
Posts: 29
Well, I cannot write into this database and need a single query to fetch the data, ideally.
Reply With Quote
  #4 (permalink)  
Old 09-24-10, 15:18
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
Its possible with a little bit crazy shit from IDS 11.50

Code:
select    *
from      (select first 500 col1, col2, col3,... from tab1)
union
select    *
from      (select first 500 col1, col2, col3,... from tab2)
order by  1;
Works with my xC6.
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