Fetch a row in a table.

  • Is it possibel to get say any row from a table withotu havinga  awhere condition. also teh tabel does have an identity colum. something like rownum =2. any help will be greatly apprecaited.

    Thanks

  • Not enough details... sample data and required results please??

  • This will fetch a row but not the row in a row position. For that we must specify a where condition.

    SET ROWCOUNT 1

    SELECT * FROM myTable

    OR

    SELECT TOP 1 * FROM myTable

    Can we ask why do you need such a select. Which row do you want to select without a where condition

    Am I 3 minutes slower than Remi

    Regards,
    gova

  • "Am I 3 minutes slower than Remi "

    That's almost a compliement to you .

  • I'm at least 3 minutes slower, if not more.

  • lets say you have 6 rows as follows. Is there a way i could get 5th row without using a where clause so that my results are EEE, 888. I know by adding an identity column  this might help but any other way out? thanks

    AAA    555

    BBB     888

    CCC    999

    DDD    777

    EEE     888

    TTT    666

     

  • You can't filter squat without a where condition.

    As for the 5th row, that's another problem altogether. What is the primary key of the table?

  • This is an unusual request indeed.

    If you don't mind can you explain what you are trying to do?

    What is the goal of writing a query without a where clause?

     

  • If this is what you want.

    HTH

    SET NOCOUNT ON

    DECLARE @MyTable TABLE

    (

    MyName VARCHAR(10),

    MyNum   INT

    )

    INSERT @MyTable

    SELECT 'AAA',    555 UNION

    SELECT 'BBB',    888 UNION

    SELECT 'CCC',    999 UNION

    SELECT 'DDD',    777 UNION

    SELECT 'EEE',    888 UNION

    SELECT 'TTT',    666

    SELECT MyName,  MyNum

    FROM

     (

     SELECT Rank = COUNT(*), T1.MyName, T1.MyNum

     FROM

      @MyTable T1, @MyTable T2

     WHERE

      T1.MyName >= T2.MyName

     GROUP BY

      T1.MyName, T1.MyNum) A

    WHERE

     Rank = 5

    Regards,
    gova

  • Thanks gusy i kneew this is indeed not diable unless you have an identity column and a where clause. BUt thought of checking up before i finally say abt this. thanks

  • Who requested this to you???

Viewing 11 posts - 1 through 10 (of 10 total)

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