You must Sign In to post a response.
  • Category: SQL Server

    Table join with limited row

    I have two table t1,t2 each records from t1 has morethan 3 records is related with t2.
    I need a join for top 3 records only from t2 table. this means each t1 records should be join with top 3 records only. please help to make this joins.
  • #767267
    use TOP class in SQL, see below query
    The SELECT TOP clause is used to specify the number of records to return.
    The SELECT TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance.

    Select TOP(3) a.*, b.ID from tbl2 a, tbl1 b
    where b.ID = a.ID

    hope it helps

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767294

    Your question give me lot of confusion any how as per my understanding I suspect that you want top 3 records based on 2 table data.

    If that is your requirement then refer below sample query

    select Top(3) a.Col1, b.col1
    from table1 a,
    table2 b

    this is sample query you can incorporate as you need.

    If you have any more queries please let us know...

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • Sign In to post your comments