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 > sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-21-10, 13:01
divak divak is offline
Registered User
 
Join Date: May 2008
Posts: 24
sql

Hi,
I have to fetch only the first and the last record from a table

For example,

SELECT FIRST 1 a.*
FROM a
ORDER BY a.f1 ASC

The above query gets me the first record of the table a ordered by field f1.

Is it possible to get the last record in the same sql?
Reply With Quote
  #2 (permalink)  
Old 09-21-10, 14:19
InformixWilli InformixWilli is offline
Registered User
 
Join Date: Sep 2010
Location: Germany, Brunswick
Posts: 52
It's not a nice solution but it's a solution

Code:
select *
from customer
where customer_num=(select min(customer_num) from customer)
or customer_num=(select max(customer_num) from customer)
Your example:
Code:
select a1.*
from a a1
where a1.f1=(select min(a2.f1) from a a2)
or a1.f1=(select max(a3.f1) from a a3)
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