Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2005
    Posts
    1

    Thumbs up Unanswered: 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

  2. #2
    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

  3. #3
    Join Date
    Sep 2002
    Posts
    102
    Its 6 records shown not 5.

  4. #4
    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);

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •