Results 1 to 2 of 2

Thread: sql

  1. #1
    Join Date
    May 2008
    Posts
    24

    Unanswered: 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?

  2. #2
    Join Date
    Sep 2010
    Location
    Germany, Brunswick
    Posts
    55
    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)

Posting Permissions

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