# Database Discussions > Sybase >  Sybase Top N in Subquery

## CMiner

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.

----------


## manost

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

----------

