dcsimg
Results 1 to 2 of 2

Thread: Sybase Top N in Subquery

  1. #1
    Join Date
    Feb 2010
    Posts
    1

    Sybase Top N in Subquery

    I know SET ROWCOUNT won't work here, I'm looking for a workable solution.

    Two database tables linked in a one-to-many relationship.

    I need to get the data from table 1, and a single field from table 2 based on the earliest date from a date field.

    In SQL it would be easy:

    SELECT Table1.*, (SELECT TOP 1 datefield FROM Table2 WHERE Table2.linkfield = Table1.linkfield ORDER BY datefield) FROM Table1

    I need some way to get the same sort of data from a Sybase database.

  2. #2
    Join Date
    Jan 2011
    Posts
    3
    You have to group rows at the second table by linkfield and then you will get the one.


    select Table1.*,Table2.id
    from etav_test1 t2 ,Table1
    where Table1.id = Table2.id group by Table2.id

Posting Permissions

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