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 > Challenging Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-14-05, 01:41
ipl ipl is offline
Registered User
 
Join Date: Oct 2005
Posts: 1
Thumbs up Challenging Question

How to retrive Records from middle of a table

suppose i have a table Employee having column Emp_Name with 5 records as shown

Emp_Name
A
B
C
D
E
F

Tell me a query that will return second record to fourth record values
ie it then return B,C,D

Regards
Reply With Quote
  #2 (permalink)  
Old 10-14-05, 06:45
habro habro is offline
Registered User
 
Join Date: Apr 2005
Posts: 3
Quote:
Originally Posted by ipl
How to retrive Records from middle of a table

suppose i have a table Employee having column Emp_Name with 5 records as shown

Emp_Name
A
B
C
D
E
F

Tell me a query that will return second record to fourth record values
ie it then return B,C,D

Regards
If you would like to get the values B,C,D then you simple create a query with the following syntax:

select emp_name from employee
where emp_name between 'B' and 'D'
order by 1;

or

select emp_name from employee
where emp_name in ('B','C','D')
order by 1


hope this helps
Reply With Quote
  #3 (permalink)  
Old 10-14-05, 08:38
blackguard blackguard is offline
Registered User
 
Join Date: Sep 2002
Posts: 102
Its 6 records shown not 5.
Reply With Quote
  #4 (permalink)  
Old 10-14-05, 08:44
blackguard blackguard is offline
Registered User
 
Join Date: Sep 2002
Posts: 102
Here is the answer:

select emp_name
from employee
where emp_name not in (select min(emp_name) from employee) and
emp_name not in (select max(emp_name) from employee);
Reply With Quote
  #5 (permalink)  
Old 10-14-05, 14:49
ifx ifx is offline
Registered User
 
Join Date: Feb 2005
Posts: 33
Hi ipl,

there is no "LIMIT 1,3" or anything else, only FIRST and MIDDLE,
but MIDDLE is not very useful in my opinion.

I suppose you want to realize a paging function.
Then I think you have to do something like this (in PHP Syntax):
$page=2;
$rows_per_page=3;
$sql="SELECT FIRST ".($page*$rows_per_page)." Emp_Name
FROM Employee";
and read over the 3 rows before your second page.

In your example you should select the first 4 and ignore the first row
in your loop routine.

As you can image this is not fast if you have to read over many rows.

If you select rows sorted by a unique key then you can use
the key of the first and last row of your current page
to jump one page forward or backward without getting
useless rows at the beginning.

Hope this helps
ifx
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