Rows in a table

  • Hi,

    I have two concerns here, plz help me out.

    1) I have one DB table with one column and with 1000 records(rows). Now I need to display the records which are from 200 to 300.

    2) Two users are entering the data in to the some DB table through application.

    Now here in this

    A) Need to display the data userwise.

    B) How to retrive the recent inserted row.

    Thanks in advance.

  • How are you going to determine rows 200 through 300? If you only have one column in this table, there is no way you can identify a row that way.

    What do you mean display the data userwise? I don't know what that means - can you provide an example?

    If you want to be able to identify the latest inserted data - you need columns in the table that identify the latest inserted data by some value. You could use an identity - and/or datetime columns.

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Hi, Thanks for your response,

    User wise means, suppose two users named A and B are entering the data at a time through the application.

    Now I need to show or display the records to A which he only entered.

    And can you explain me about identity, what it is and how this will be useful. Please.

    Thanks in advance.

  • You need to expand your table. Having a identity column which contains a key. Plus a column to store who updates the record.

    Table

    IdentityCol - 1,2,3 etc

    ValueCol - the value you currently store

    UserCol - the user that created the row

    Then you can filter results on usercol.

  • Maybe you could use the ROW_NUMBER() function, something like this:

    WITH ResultSet AS (

    SELECT ROW_NUMBER() OVER (ORDER BY Column1 )

    AS Row, Column1

    FROM MyTable)

    SELECT *

    FROM ResultSet

    WHERE Row between 200 and 300

    Greetz,
    Hans Brouwer

  • FreeHansje (10/14/2009)


    Maybe you could use the ROW_NUMBER() function, something like this:

    WITH ResultSet AS (

    SELECT ROW_NUMBER() OVER (ORDER BY Column1 )

    AS Row, Column1

    FROM MyTable)

    SELECT *

    FROM ResultSet

    WHERE Row between 200 and 300

    Before we can get to using row_number() - we need to be able to uniquely identify the row. If the table has an identity column, that can be used to order the rows - or, if there is a CreatedDate column and a username, those could be used.

    But first we need the OP to define how we get to row 200 - what tells us that the row we return is actually the 200th row?

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply